[R] Exclude missing values on only 1 variable

David Winsemius dwinsemius at comcast.net
Thu Jul 5 21:35:10 CEST 2012


On Jul 5, 2012, at 1:34 PM, David Winsemius wrote:

>
> On Jul 5, 2012, at 1:25 PM, Eiko Fried wrote:
>
>> Hello,
>>
>> I have many hundred variables in my longitudinal dataset and lots of
>> missings. In order to plot data I need to remove missings.
>>
>> If I do
>>> data <- na.omit(data)
>> that will reduce my dataset to 2% of its original size ;)
>>
>> So I only need to listwise delete missings on 3 variables (the ones  
>> I am
>> plotting).
>>
>> data$variable1 <-na.omit(data$variable1)
>
> ?complete.cases  # returns a logical vector
>
> data[ complete.cases( data[ , c("var1", "var2", "var3"]) , ]
>
> data[ complete.cases( data[ , c("var1", "var2", "var3") ] ) , ]
Er, need to add a right - paren  -----here  -----------^
>
-- 

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list