Wacek Kusnierczyk wrote:
> Milton Huang wrote:
>   
>> Dear list members:
>>
>> I am looking for an elegant (or efficient) way to accomplish the following:
>>
>> take a large boolean vector and fill the TRUE values with the values from a 
>> smaller boolean vector that has a length that is the number of TRUE values 
>> of 
>> the large vector.
>>
>> Example:
>>
>> large<- c(FALSE, FALSE, FALSE, TRUE, FALSE, FALSE,  TRUE, FALSE, FALSE, 
>> FALSE,  
>> TRUE, FALSE)
>>
>> small<- c(TRUE, FALSE, TRUE)
>>
>> desired output = c(FALSE, FALSE, FALSE, *TRUE*, FALSE, FALSE,  *FALSE*, 
>> FALSE, 
>> FALSE, FALSE, *TRUE*, FALSE)
>>
>>   
>>     
>
> large[which(large)] = small
> # large[which(large)] = paste("*", small, "*", sep="") to see it's as
> you specify
> ?which
>   

oops, i read your mail too quickly, assumed you wanted to make an
in-place replacement.  the functional way would be:

replace(large, which(large), small)

vQ

______________________________________________
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