[R] how to ignore NA with "NA" or "NULL"

jeff6868 geoffrey_klein at etu.u-bourgogne.fr
Wed Jun 6 17:42:33 CEST 2012


Thanks again for your help jeff.
Sorry if I'm not very clear. It's programmingly speaking hard to explain,
and even to explain in english as I'm French.
But i'll try again.

Well your proposition removes the error, but it's not the result I'm
expecting. You've removed NULL data.frames, but I need to keep them, well
not to keep them but to transform them to something non-NULL actually.

I'll try to show you in a very small and fake exemple what I want results to
be:
Imagine these are my 3 input data frames (10 rows each):
ST1 <- data.frame(x1=c(1:10))
ST2 <- data.frame(x2=c(1:5,NA,NA,8:10))
ST3 <- data.frame(x3=c(NA,NA,NA,NA,NA,NA,NA,NA,NA,NA))

The aim of my code is to fill all the NA of my data.frames with data,
according to the correlation coefficient  of my data.frames(for example, if
there're NAs in ST1, ST1 must be filled with data from the best correlated
file with ST1 (between ST2 and ST3 in this example)).

As ST3 has no data, I cannot have any correlation coefficient. So NAs from
ST3 cannot be filled, and ST3 cannot also be used to fill another file. So
ST3 has no use if you want. Nevertheless I want to keep ST3 unchanged during
all my code.
For the moment my code would give for "refill" this (filled NA in my
data.frames):

ST1 <- data.frame(x1=c(1:10))
ST2 <- data.frame(x2=c(1:5,6,7,8:10))
ST3 <- NULL

But actually, I want for results in "refill" this: 

ST1 <- data.frame(x1=c(1:10))
ST2 <- data.frame(x2=c(1:5,6,7,8:10))
ST3 <- data.frame(x3=c(NA,NA,NA,NA,NA,NA,NA,NA,NA,NA))

So for data.frames with only NAs, I don't want them to be NULL in "refill",
but I want them to be identical as in input. I need this to have the same
dimensions of data.frames between inputs and outputs.
If I set them as NULL (like it is for the moment but I don't understand why
and I want to change this), there will be 0 rows in this data.frame instead
of 10 rows like the other data.frames. 

So I think there's something wrong in my code in function "process.all" or
"na.fill" or maybe "lst".
We don't seem to be far from the solution but I still don't find it for the
moment.
For information, in function "process.all" and "na.fill": x is the
data.frame I want to fill, and y is the file which will be used to fill x
(so the best correlated file with x).

I really hope I've been enoughly clear and understandable this time.
Thank you!



--
View this message in context: http://r.789695.n4.nabble.com/how-to-ignore-NA-with-NA-or-NULL-tp4632287p4632546.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list