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]]
HI, Assuming the structure is similar to this: set.seed(15) list1<-lapply(c(60,120),function(i) as.data.frame(matrix(sample(1:100,240,replace=TRUE),nrow=i))) # with 2 list elements ?lapply(list1,function(x) x[-c(32,64,96,128,160,192),]) A.K. ----- Original Message ----- From: eliza botto <eliza_botto at hotmail.com> To: "r-help at r-project.org" <r-help at r-project.org> Cc: Sent: Wednesday, January 2, 2013 12:00 PM Subject: [R] loop correction needed 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]] ______________________________________________ R-help at 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.
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