Alex Rivera | Logout

How to convert row names of table into a vector

Asked 2011-10-18T00:18:37.360
9

I have returned stats on my data using the table command as such:

subject<-c(4,4,2,2,3,3)
correct<-c(0,1,1,1,0,0)
test<-data.frame(subject,correct)
freq_test<-head(table(test$subject,test$correct))

This returns a table which looks like this

    0 1

  2 0 2

  3 2 0

  4 1 1

That's great, but the problem is that I would like, the first column to be a vector rather than row.names (so that I can code it properly as "subject"). Is there a way to get this column to act in this way?

r
Edit
Report

1 Answer

0

I think you should have used the standard method of construction of a data.frame, which is with name=values pairs:

test <- data.frame( subject=subject, correct=correct)

The first subject will be interpreted as a name to be quoted and the second subject will be interpreted .... i.e, the enclosing environments will be searched for an object named subject and its value will be assigned to the "subject" column of "test".

answered 2011-10-18T00:54:57.120

Your Answer