[R] different functions on different vector subsets

Ron Ophir ron.ophir at weizmann.ac.il
Fri Nov 11 12:48:23 CET 2005


I thought about other cases but I have to dissagree with you. For
logical vector NA is no decision and that should be the results of it.
Let's say that -b- is a result of comparison not of -a- to something 
rather a compsrison of -c- to -d-. In this case NA in the first position
is a result of NA in either -c- or -d- or both. Now, if the result I
wanted to get from your example

a<-c(1,2,3,4)
b<-c(NA,T,F,T)

a[b]<-7
 is c(1,7,7,7) I should replace the NA (no decision) with F and if to
get c(7,7,7,7)  the NA should be replaced by T otherwise the result
should be c(NA,7,7,7). The first two option are possible to perform in R
 the third is not and that is to the user to decide which to choose.
Ron

>>> Thomas Lumley <tlumley at u.washington.edu> 11/10/05 11:02 PM >>>
On Thu, 10 Nov 2005, Ron Ophir wrote:

> Thanks Thomas,
>
> "...For logical subscripts you could argue that the
> ambiguity isn't present and that if the index was NA the element
should
> just be set to NA. This change might be worth making."
>
> I see you got my point. NA should return NA no matter what the
> comparison is.

I'm not sure that I did get your point.  As Brian said, you aren't 
specifying whether or not to set the value. In your example it didn't 
matter because it would end up NA either way.

I was saying that for eg

a<-c(1,2,3,4)
b<-c(NA,T,F,T)

a[b]<-7

we could relax the prohibition on NA indexing to give c(NA,7,7,7) as the

result. In your case that would give what you wanted, but in other cases

it might not.


 	-thomas




More information about the R-help mailing list