Hello!

The code below works and does what I need it to do.
However, I think the way I create myframe (last step) is very
un-R-like and probably not very efficient. I am sure there are better,
more R-appropriate methods.
Any pointers?
Thanks a lot!
Dimitri

# Step 1: Creating a vector of dates:
mydates<-seq(as.Date("2008-12-29"), length = 50, by = "week")
(mydates)

# Step 2: Creating a vector of units:
units<-1:20
(units)

### Step3: Creating a data frame with 2 columns: all units stacked
(col 1) with all dates in each (col 2):
myframe<-NULL
for(i in 1:length(units)){  # i<-1
  myframe[[i]]<-data.frame(unit=rep(units[i],length(mydates)),Weeks=mydates)
}
myframe<-do.call(rbind,myframe)
str(myframe)
head(myframe,110)


-- 
Dimitri Liakhovitski
Ninah Consulting
www.ninah.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.

Reply via email to