3

I have a table object in R. It looks a bit like this:

           2422 2581 3363
  16566    0    1    0
  16568    0    2    0
  16598    0    1    0
  16627    0    1    0
  16683    0    1    0
  16701    0    1    0
  16740    0    1    0
  16741    0    1    0

I'd like to convert it to a data frame, whereby this data frame should have 4 variables, not 3. In other words, the first column, 16566, 16568, etc. should be a variable - let's call it ID. The other variables should be the 2422, 2581, 3363 columns.

I've tried as.data.frame() and as.data.frame.matrix() but both functions somehow swallow the first column.

Thanks in advance for your help!

nikUoM
  • 639
  • 1
  • 8
  • 18

1 Answers1

6
df <- as.data.frame(table)
df$ID <- rownames(table)
Alex P
  • 1,574
  • 13
  • 28