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

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Haillie
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
Reply | Threaded
Open this post in threaded view
|

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

John Kane-2
Why not just data.matrix(UN2010) ?

--- On Wed, 4/20/11, Haillie <[hidden email]> wrote:

> From: Haillie <[hidden email]>
> Subject: [R] Unlist command drops all my column names in the first row and adopts NAs
> To: [hidden email]
> 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.
>
> ______________________________________________
> [hidden email]
> 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.
>

______________________________________________
[hidden email] 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.