1

I used the code below for cross tabulation:

data=table(subset(datGSS, select = c("sex", "happy")))

In this result format is saved into values format but I would need output saved into dataset format.

Can any one help me in this regard?

rawr
  • 20,481
  • 4
  • 44
  • 78
  • Welcome to StackOverflow. Please read [how do I ask a good question](http://stackoverflow.com/help/how-to-ask) and [proding a minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example#answer-5963610) and edit your post accordingly. I.e., provide input data, the expected output format + what you tried and in what way it failed. – lukeA Apr 16 '16 at 11:58

1 Answers1

0

You can pass the result of table to data.frame (or as.data.frame). I guess, data.frame(data) should do the job for you but here is an example on a simple data.frame (your example was not reproducible) :

df <- data.frame(col1=factor(letters[1:4]), 
                 col2=factor(LETTERS[1:2]))
> table(df)
col2
col1 A B
a 1 0
b 0 1
c 1 0
d 0 1

To convert it to a data.frame (the "dataset" class does not exist in R):

> as.data.frame(table(df))
  col1 col2 Freq
1    a    A    1
2    b    A    0
3    c    A    1
4    d    A    0
5    a    B    0
6    b    B    1
7    c    B    0
8    d    B    1

Is this what you want?

Also, note that RStudio is "just" an IDE for R. So that's more an R question than an RStudio one.

Community
  • 1
  • 1
Vincent Bonhomme
  • 7,235
  • 2
  • 27
  • 38