> I ran into some trouble handling missing values.
> 
> Assume 2 vectors (numeric) including NAs
> 
> a <- c(rep(seq(1,4),4),NA,NA)
> b <- c(sample(1:2,14,replace=T),NA,NA,1,2)
> 
> 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[b==1][a[b==1]<2 | a[b==1]>3] <- NA
> The following error accurse:
> NAs are not allowed in subscripted assignments

You were nearly right - you just had an extra index that you didn't need. 
Try:
a[a[b==1]<2 | a[b==1]>3] <- NA

Regards,
Richie.

Mathematical Sciences Unit
HSL


------------------------------------------------------------------------
ATTENTION:

This message contains privileged and confidential inform...{{dropped:20}}

______________________________________________
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