[R] convert data.frame to matrix -> NA factor problem

Joshua Wiley jwiley.psych at gmail.com
Wed Jul 14 16:30:38 CEST 2010


Hi,

Can you show the results of str() on your original dataframe?  Also it
would help if you could make an example that demonstrates your
problem.  I used this little example, and did not notice any problems:

samp.frame <- data.frame(a = 1:10, b = c(3,2,5,3,1,5,NA,4,5,NA))
str(samp.frame)
samp.matrix <- data.matrix(samp.frame)
str(samp.matrix)

Best regards,

Josh

On Wed, Jul 14, 2010 at 7:18 AM, syrvn <mentor_ at gmx.net> wrote:
>
> Hi list,
>
> I tried to convert a data.frame into a matrix using data.matrix.
> Unfortunately my matrix contains missing values (NA) wherefore all columns
> including NA's were changed into factors.
>
> I thought that many people stumbled across that problem already wherefore
> there must be a
> simple solution. But it seems there isn't. I tried lapply, replace and other
> things in combination
> but still did not manage to convert my data.frame into a proper matrix with
> numeric values.
>
> Any advice?
> Cheers
> --
> View this message in context: http://r.789695.n4.nabble.com/convert-data-frame-to-matrix-NA-factor-problem-tp2288828p2288828.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.
>



-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
http://www.joshuawiley.com/



More information about the R-help mailing list