[R] RE: Matrix to data.frame without factors

Mäkinen Jussi Jussi.Makinen at valtiokonttori.fi
Fri Apr 12 11:31:47 CEST 2002


>> To answer at least partially to my own question:
>>
>> "na.to.0" <- function(x)
>> {
>> 	xx <- data.matrix(x)
>> 	xx[is.na(x)] <- 0
>> 	xx <- data.frame(xx)
>> 	xx
>> }
>>
>> seems to work (Idea is/was replace a data.frame NAs by 0s and return =
a
>> data.frame as a result).
>>
>> Still I'm a little bit confused with these converts but now I can mov=
e on.

>I'm confused by your questions.  Is this a data frame with only numeric
>columns?   If so, your comments about factors/characters make no sense,=
> and
>if not your conversion makes little sense.

>=46or a *numeric* data frame X

>X[] <- lapply(X, function(x) {x[is.na(x)] <- 0; x})

>seems to be what you want.

Here is a sample of my data.frame (KUNTADATA):



-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._



More information about the R-help mailing list