[R] Creating a list of combinations

Steve Murray smurray444 at hotmail.com
Thu Aug 20 14:04:36 CEST 2009


Dear R Users,

I have 120 objects stored in R's memory and I want to pass the names of these many objects to be held as just one single object. The naming convention is month, year in sequence for all months between January 1986 to December 1995 (e.g. Jan86, Feb86, Mar86... through to Dec95). I hope to pass all these names (and their data I guess) to an object called file_list, however, I'm experiencing some problems whereby only the first (and possibly last) names seem to make the list, with the remainder recorded as 'NA' values.

Here is my code as it stands:

index <- expand.grid(month=month.abb, year=seq(from=86,to=95, by=1))

for (i in seq(nrow(index))) {
    file_list <- paste(index$month[i], index$year[i], sep='')
    print(file_list[i])
    }

Output is as follows:

[1] "Jan86"
[1] NA
[1] NA
[1] NA
#[continues to row 120 as NA]

> file_list; file_list[i]
[1] "Dec95"
[1] NA

> head(index) # this seems to be working fine
  month year
1   Jan   86
2   Feb   86
3   Mar   86
4   Apr   86
5   May   86
6   Jun   86


Any help on how I can populate file_list correctly with all 120 combinations of month + year (without NAs!) would be gratefully received.

Thanks,

Steve



_________________________________________________________________

icons.




More information about the R-help mailing list