[R] loop correction needed

David Winsemius dwinsemius at comcast.net
Wed Jan 2 19:17:09 CET 2013


On Jan 2, 2013, at 9:00 AM, eliza botto wrote:

>
> Dear useRs,
> i have a data frame with 16 lists in it. each list has variable  
> number of lines. i want to create a loop which will start deleting  
> every 32nd line in each list, till the end of each list. more  
> precisely if a list has 200 rows i want to delete row number 32, 64,  
> 96 and so on...for that i created the followng loop.
>> e<-lapply(seq(1),function(i) rbind(r[[i]][1:31,],(r[[i]] 
>> [32:nrow(r[[i]]),][-seq(i,nrow(r[[i]]),32),])))
> but this loop executes the desired operation on the list at the top  
> and doesnt do anything to the remaining 16 lists.
> any help?thanks in advance
> eliza 		 	   		
> 	[[alternative HTML version deleted]]


Perhaps something like this untested code:

smaller.r <- lapply(r, function(x) x[ ! ( 1:200 %% 32 == 0) ] ) #  
logical indexing

You _should_ have constructed a small example and posted the results  
of dput on that list.

-- 


David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list