Re: [R] NAs - NAs are not allowed in subscripted assignments

From: Nordlund, Dan (DSHS/RDA) <NordlDJ_at_dshs.wa.gov>
Date: Thu, 24 Jul 2008 09:30:54 -0700

> -----Original Message-----
> From: r-help-bounces_at_r-project.org
> [mailto:r-help-bounces_at_r-project.org] On Behalf Of Gabor Csardi
> Sent: Thursday, July 24, 2008 8:39 AM
> To: Kunzler, Andreas
> Cc: r-help_at_r-project.org; r-help-bounces_at_r-project.org;
> Richard.Cotton_at_hsl.gov.uk
> Subject: Re: [R] NAs - NAs are not allowed in subscripted assignments
>
> On Thu, Jul 24, 2008 at 04:45:14PM +0200, Kunzler, Andreas wrote:
> > Hy Richie, thank you for the quick response.
> >
> > Unfortunately my problems hold on.
> >
> > Once again: 2 vectors (numeric) including NAs
> > My intention: I want to replace the values of vector a that
> are smaller
> > than 2 and larger than 3 into NAs only in case vector b equals 1
> >
> > a <- c(rep(seq(1,4),4),NA,NA)
> > b <- c(rep(seq(1,2),7),NA,NA,1,2)
>
> Andreas,
>
> what is wrong with
>
> a[ (a < 2 | a > 3) & b==1 ] <- NA
>
> ? Isn't this what you want?
>

> Btw. I assume you mean replacing values that are either smaller than
> 2 _OR_ larger than 3, no number is smaller than 2 _AND_ larger than 3,
> at least if we consider the usual ordering on numbers.
>
> Best,
> Gabor
>
> [...]
>
> --
> Csardi Gabor <csardi_at_rmki.kfki.hu> UNIL DGM

As I mentioned in my response to this thread, there are some things I don't quite understand with logical indexing. Using the above example,

> a[ (a < 2 | a > 3) & b==1 ]

returns

[1] 1 1 1 1 NA NA

Where do the NA values come from?

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division
Olympia, WA 98504-5204    



R-help_at_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. Received on Thu 24 Jul 2008 - 16:44:42 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 24 Jul 2008 - 17:32:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive