Your assignment of NAs is fine.

When you extract, you have to remember to specify whether you want to
include or exclude those NA values.

Try this:
     data1.long[data1.long$time==9 & !is.na(data1.long$time), "time"]

Jean



On Tue, Jan 14, 2014 at 7:22 AM, Chia-Chieh Lin <chiaowlet@yahoo.com.tw>wrote:

> Hi all,
>
> I have a data set, named ．data1.long・,
> which has 180 subjects with two variables, ．time・ and ．patient・. The ．time・
> variable takes 9 values, i.e., 1, 2, 3,�K,9, and the ．patient・ variable
> takes
> two values, 0 and 1. There are 10 subjects for each combination of ．time・
> and ．patient・.
> And there are no missing values for the two variables.
>
> I then assign NAs to the ．time・ variable
> for 10 subjects by doing:
> data1.long[data1.long$time==5 &
> data1.long$patient==0, "time"] <- NA
>
> Then I check the result using:
> data1.long[data1.long$time==9,
> "time"]
>
> R returns
> [1]  9  9  9 NA NA  9 NA  9  9  9  9  9 NA  9  9 NA  9 NA  9  9 NA  9 NA  9
> NA  9  9  9 NA  9
>
> where I should・ve gotten 20 9・s. Another
> checking is this:
> data1.long[data1.long$time==9 &
> data1.long$patient==0, "time"]
>
> which should give me 10 9・s but instead, it
> returns
> [1]  9 NA NA  9 NA  9 NA  9
> NA  9 NA  9  9 NA NA  9 NA  9  9 NA
>
> Is there anything wrong with my assigning
> of NA values?
>
> Thank you for the help.
>
> Chia-Chieh Lin
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> 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.
>
>

	[[alternative HTML version deleted]]

