Unlist command drops all my column names in the first row and adopts NAs

#1
Hi Everyone,

I am having trouble turning my data.frame into a matrix format. Because I wanted to change my data.frame with mostly factor variables into a numeric matrix, I used the following code --> UN2010frame<-data.matrix(lapply(UN2010,as.numeric))

However when i checked the mode of the UN2010frame, it still showed up as a list. Because the code I want to run (Ordrating) does not accept data in a list format, I used UN2010matrix <- unlist(UN2010frame) to unlist my matrix. When I did this, my first row ( which was formerly a row with column names) turned into NAs. This was a problem for me because when I tried to run an ordinal IRT model using this data set, I got the following error message.

Error in 1:nrow(Y) : argument of length 0

I think it is because all the values in my first row are now gone....

If you could help me on any front, It would be deeply appreciated. Thank you very much!

Haillie
 

Dason

Ambassador to the humans
#2
I'm not exactly sure what's going on there (I didn't really delve into what you were going into). But if you want to change a data.frame into a numeric matrix for the use of modeling you might want to consider the 'model.matrix' function.
Code:
> X
  x   age
1 1   old
2 2   old
3 3 young
> model.matrix(~ x + age, data = X)
  (Intercept) x ageyoung
1           1 1        0
2           1 2        0
3           1 3        1
attr(,"assign")
[1] 0 1 2
attr(,"contrasts")
attr(,"contrasts")$age
[1] "contr.treatment"