[R] different functions on different vector subsets

Thomas Lumley tlumley at u.washington.edu
Fri Nov 11 18:25:55 CET 2005


On Fri, 11 Nov 2005, Ron Ophir wrote:

> 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.

I would say NA is "missing": it means that the result could be any valid 
value and we don't know which one it is.  That's how NA works in all other 
computations. It doesn't really affect your argument below, though.

> 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.

But as Brian pointed out, what if a is a list? There is no NA value for 
the list type.  So assignment with an NA subscript cannot be made 
consistent across even the basic vector types.

 	-thomas


> 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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle




More information about the R-help mailing list