Hi You have got several suggestions. When I try your code I get only errors, not list or any other objects.
> x<-unique(Returns.names$date_) Error in unique(Returns.names$date_) : object 'Returns.names' not found > n<-1 > while(n<=19) { + Returns.period<-lapply(((n-1)*125+1):((n+1)*125), function (i) + which(Returns.filter$date_==x[i])) + Returns.period<-unlist(Returns.period) + + Returns.period1[n,1:(length(Returns.period))]<-Returns.filter[Returns.period,] + n<-n+1 + } Error in which(Returns.filter$date_ == x[i]) : object 'Returns.filter' not found > How do you expect to get reasonable help if you can not present what you did and how result differ from what you want on some fake data which we can copy to R. r-help-boun...@r-project.org napsal dne 09.06.2010 03:49:37: > > Dear R Gurus, > > Thanks for any help in advance! > > Date.frame: Returns.names > > X id ticker date_ adjClose totret RankStk > 258060 258060 13645T10 CP 2001-06-29 18.125 1877.758 > > My data frame is in the above format. I would like to filter by period, per what is filter?? Help page says Description Applies linear filtering to a univariate time series or to each series separately of a multivariate time series. > id (every 125 days) each consisting of 250 days, I.e. 1-250, 126-375, etc. <snip> > Thus, I tried to adjust by dynamically assigning each period to a column. > However, I get the error: object 'Returns.period1' not found. And R is not > like Java where you can simply declare a variable by typing say > Returns.period1. Why do you expect that one language will behave the same way as another language. If R was like Java what would be the reason to have 2 languages? Try instead to comply posting guide and make a fake data which can be directly used e.g. by dput, construct a result which is to be achieved and present a code which can be copied to R and which gives other then expected result. After that we can quit guessing and start providing relevant help. Regards Petr > > I do not know how to create a flexible empty matrix that would allow this > code to work. > > If anyone knows how to do this without a loop, that would be even better! > > ##Filtering by Period > n<-1 > while(n<=19) { > Returns.period<-lapply(((n-1)*125+1):((n+1)*125), function (i) > which(Returns.filter$date_==x[i])) > Returns.period<-unlist(Returns.period) > > Returns.period1[n,1:(length(Returns.period))]<-Returns.filter[Returns.period,] > n<-n+1 > } > > -- > View this message in context: http://r.789695.n4.nabble.com/Extracting- > Elements-By-Date-tp2248227p2248227.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. ______________________________________________ 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.