D. Alain wrote:

> Now I want to make a new dataframe df.sub comprising only cases pertaining
> to groups, where the overall proportion of NAs in either of the response
> variables y,z,w does not exceed 50%.

One simple example:

library(plyr)
na.prop = function(x) data.frame(x, missing=nrow(na.omit(x))/nrow(x) )
newdf = ddply(df, .(x), na.prop)

Now you can use ‘subset’ on ‘newdf’ to obtain the required rows.

(For very large data sets it may be better to not create an entire data 
frame in ‘na.prop’, duplicating the data in ’df’, but instead just return 
the proportion.)
 
-- 
Karl Ove Hufthammer

______________________________________________
R-help@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.

Reply via email to