Skip to content
Back to formatted view

Raw Message

Message-ID: <49520501.3000903@idi.ntnu.no>
Date: 2008-12-24T09:46:41Z
From: Wacek Kusnierczyk
Subject: filling values in a vector using smaller vector
In-Reply-To: <495200C5.2060707@idi.ntnu.no>

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)
>>>
>>>
>>>       
> replace(large, which(large), small)
>   

in fact, this will do:

replace(large, large, small)

vQ