Hi Peter,

I think you want

tmp1$Q.4[tmp1$Q.4 != 1 & tmp1$Q.4 != 5] <- NA
tmp1
#Date HrMn  Temp Q.4
# 1 19450101  900 -37.0   1
# 2 19450101 1000 -35.9  NA
# 3 19450101 1100 -35.9  NA
# 4 19450101 1200 -36.4  NA
# 5 19450101 1300 -36.4   5
# 6 19450101 1400 -36.4  NA
# 7 19450101 1500 -36.4  NA
# 8 19450101 1600 -37.5  NA

(note the ".4" after Q).

HTH,
Jorge

On Fri, Mar 19, 2010 at 3:38 PM, Peter Keller <> wrote:

>
>
> data:
> > tmp1
>      Date HrMn  Temp Q.4
> 1 19450101 0900 -37.0   1
> 2 19450101 1000 -35.9   2
> 3 19450101 1100 -35.9   3
> 4 19450101 1200 -36.4   4
> 5 19450101 1300 -36.4   5
> 6 19450101 1400 -36.4   6
> 7 19450101 1500 -36.4   7
> 8 19450101 1600 -37.5   9
>
> Accidentally, I did this (I meant to write Q.4 instead of Q here)
> > tmp1$Q[tmp1$Q!="1" & tmp1$Q!= "5"]<-NA
>
> I would have expected it to tank, but still got a new field with the the
> values I wanted
> > tmp1
>      Date HrMn  Temp Q.4    Q
> 1 19450101 0900 -37.0   1    1
> 2 19450101 1000 -35.9   2 <NA>
> 3 19450101 1100 -35.9   3 <NA>
> 4 19450101 1200 -36.4   4 <NA>
> 5 19450101 1300 -36.4   5    5
> 6 19450101 1400 -36.4   6 <NA>
> 7 19450101 1500 -36.4   7 <NA>
> 8 19450101 1600 -37.5   9 <NA>
>
> Can someone explain this?
> Peter
>
> > sessionInfo()
> R version 2.10.1 Patched (2010-03-16 r51294)
> i386-pc-mingw32
>
> locale:
> [1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United
> States.1252
> [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C
> [5] LC_TIME=English_United States.1252
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] lattice_0.18-3 fortunes_1.3-7 zoo_1.6-2
>
> loaded via a namespace (and not attached):
> [1] grid_2.10.1  tools_2.10.1
>
> --
> View this message in context:
> http://n4.nabble.com/strange-behavior-adds-new-field-by-non-existent-field-tp1603563p1603563.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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]]

