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

John Kane jrkrideau at yahoo.ca
Wed Apr 20 17:27:56 CEST 2011


Why not just data.matrix(UN2010) ?

--- On Wed, 4/20/11, Haillie <nal at princeton.edu> wrote:

> From: Haillie <nal at princeton.edu>
> Subject: [R] Unlist command drops all my column names in the first row and adopts NAs
> To: r-help at r-project.org
> Received: Wednesday, April 20, 2011, 11:05 AM
> 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 
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Unlist-command-drops-all-my-column-names-in-the-first-row-and-adopts-NAs-tp3463294p3463294.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> ______________________________________________
> R-help at r-project.org
> mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>



More information about the R-help mailing list