Hi

Thanks for your help. I feel like Im definitely getting closer. The list that this code makes has a bunch of repeats which I do not want. Ie 2040a1b_cgcm3 repeats a couple times ( I think maybe 12 times, once for each month) I only want it to be there once. So I should end up with 12x2=24 model/year permutations. Also I tried to raster this list and realised that I can’t raster a list but need a character file to do this. I have code which takes works on character files from this point but only with one of the models/years. I was trying to automate it a little more. Any help would be appreciated

Thanks

Kanika

From: romunov@gmail.com [mailto:romunov@gmail.com] On Behalf Of Roman Luštrik
Sent: Sunday, 4 March 2012 3:10 a.m.
To: Kanika Jhunjhnuwala
Subject: Re: [R-sig-Geo] looping over files

Try this and let me know if it's what you were looking for.

knk <- c("tas_2040a1b_apr_cccma_cgcm3.txt", "tas_2040a1b_apr_cnrm_cm3.txt",
                        "tas_2040a1b_apr_csiro_mk30.txt", "tas_2040a1b_apr_gfdl_cm20.txt",
                        "tas_2040a1b_apr_gfdl_cm21.txt", "tas_2040a1b_apr_miroc32_hires.txt",
                        "tas_2040a1b_apr_miub_echog.txt", "tas_2040a1b_apr_mpi_echam5.txt",
                        "tas_2040a1b_apr_mri_cgcm232.txt", "tas_2040a1b_apr_ncar_ccsm30.txt",
                        "tas_2040a1b_apr_ukmo_hadcm3.txt", "tas_2040a1b_apr_ukmo_hadgem1.txt",
                        "tas_2040a1b_aug_cccma_cgcm3.txt", "tas_2040a1b_aug_cnrm_cm3.txt",
                        "tas_2040a1b_aug_csiro_mk30.txt", "tas_2040a1b_aug_gfdl_cm20.txt",
                        "tas_2040a1b_aug_gfdl_cm21.txt", "tas_2040a1b_aug_miroc32_hires.txt",
                        "tas_2040a1b_aug_miub_echog.txt", "tas_2040a1b_aug_mpi_echam5.txt",
                        "tas_2040a1b_aug_mri_cgcm232.txt", "tas_2040a1b_aug_ncar_ccsm30.txt",
                        "tas_2040a1b_aug_ukmo_hadcm3.txt", "tas_2040a1b_aug_ukmo_hadgem1.txt",
                        "tas_2040a1b_dec_cccma_cgcm3.txt", "tas_2040a1b_dec_cnrm_cm3.txt",
                        "tas_2040a1b_dec_csiro_mk30.txt", "tas_2040a1b_dec_gfdl_cm20.txt",
                        "tas_2040a1b_dec_gfdl_cm21.txt", "tas_2040a1b_dec_miroc32_hires.txt",
                        "tas_2040a1b_dec_miub_echog.txt", "tas_2040a1b_dec_mpi_echam5.txt",
                        "tas_2040a1b_dec_mri_cgcm232.txt", "tas_2040a1b_dec_ncar_ccsm30.txt",
                        "tas_2040a1b_dec_ukmo_hadcm3.txt", "tas_2040a1b_dec_ukmo_hadgem1.txt",
                        "tas_2040a1b_feb_cccma_cgcm3.txt", "tas_2040a1b_feb_cnrm_cm3.txt",
                        "tas_2040a1b_feb_csiro_mk30.txt", "tas_2040a1b_feb_gfdl_cm20.txt",
                        "tas_2040a1b_feb_gfdl_cm21.txt", "tas_2040a1b_feb_miroc32_hires.txt",
                        "tas_2040a1b_feb_miub_echog.txt", "tas_2040a1b_feb_mpi_echam5.txt",
                        "tas_2040a1b_feb_mri_cgcm232.txt", "tas_2040a1b_feb_ncar_ccsm30.txt",
                        "tas_2040a1b_feb_ukmo_hadcm3.txt", "tas_2040a1b_feb_ukmo_hadgem1.txt",
                        "tas_2040a1b_jan_cccma_cgcm3.txt", "tas_2040a1b_jan_cnrm_cm3.txt",
                        "tas_2040a1b_jan_csiro_mk30.txt", "tas_2040a1b_jan_gfdl_cm20.txt",
                        "tas_2040a1b_jan_gfdl_cm21.txt", "tas_2040a1b_jan_miroc32_hires.txt",
                        "tas_2040a1b_jan_miub_echog.txt", "tas_2040a1b_jan_mpi_echam5.txt",
                        "tas_2040a1b_jan_mri_cgcm232.txt", "tas_2040a1b_jan_ncar_ccsm30.txt",
                        "tas_2040a1b_jan_ukmo_hadcm3.txt", "tas_2040a1b_jan_ukmo_hadgem1.txt",
                        "tas_2040a1b_jul_cccma_cgcm3.txt", "tas_2040a1b_jul_cnrm_cm3.txt",
                        "tas_2040a1b_jul_csiro_mk30.txt", "tas_2040a1b_jul_gfdl_cm20.txt",
                        "tas_2040a1b_jul_gfdl_cm21.txt", "tas_2040a1b_jul_miroc32_hires.txt",
                        "tas_2040a1b_jul_miub_echog.txt", "tas_2040a1b_jul_mpi_echam5.txt",
                        "tas_2040a1b_jul_mri_cgcm232.txt", "tas_2040a1b_jul_ncar_ccsm30.txt",
                        "tas_2040a1b_jul_ukmo_hadcm3.txt", "tas_2040a1b_jul_ukmo_hadgem1.txt",
                        "tas_2040a1b_jun_cccma_cgcm3.txt", "tas_2040a1b_jun_cnrm_cm3.txt",
                        "tas_2040a1b_jun_csiro_mk30.txt", "tas_2040a1b_jun_gfdl_cm20.txt",
                        "tas_2040a1b_jun_gfdl_cm21.txt", "tas_2040a1b_jun_miroc32_hires.txt",
                        "tas_2040a1b_jun_miub_echog.txt", "tas_2040a1b_jun_mpi_echam5.txt",
                        "tas_2040a1b_jun_mri_cgcm232.txt", "tas_2040a1b_jun_ncar_ccsm30.txt",
                        "tas_2040a1b_jun_ukmo_hadcm3.txt", "tas_2040a1b_jun_ukmo_hadgem1.txt",
                        "tas_2040a1b_mar_cccma_cgcm3.txt", "tas_2040a1b_mar_cnrm_cm3.txt",
                        "tas_2040a1b_mar_csiro_mk30.txt", "tas_2040a1b_mar_gfdl_cm20.txt",
                        "tas_2040a1b_mar_gfdl_cm21.txt", "tas_2040a1b_mar_miroc32_hires.txt",
                        "tas_2040a1b_mar_miub_echog.txt", "tas_2040a1b_mar_mpi_echam5.txt",
                        "tas_2040a1b_mar_mri_cgcm232.txt", "tas_2040a1b_mar_ncar_ccsm30.txt",
                        "tas_2040a1b_mar_ukmo_hadcm3.txt", "tas_2040a1b_mar_ukmo_hadgem1.txt",
                        "tas_2040a1b_may_cccma_cgcm3.txt", "tas_2040a1b_may_cnrm_cm3.txt",
                        "tas_2040a1b_may_csiro_mk30.txt", "tas_2040a1b_may_gfdl_cm20.txt",
                        "tas_2040a1b_may_gfdl_cm21.txt", "tas_2040a1b_may_miroc32_hires.txt",
                        "tas_2040a1b_may_miub_echog.txt", "tas_2040a1b_may_mpi_echam5.txt",
                        "tas_2040a1b_may_mri_cgcm232.txt", "tas_2040a1b_may_ncar_ccsm30.txt",
                        "tas_2040a1b_may_ukmo_hadcm3.txt", "tas_2040a1b_may_ukmo_hadgem1.txt",
                        "tas_2040a1b_nov_cccma_cgcm3.txt", "tas_2040a1b_nov_cnrm_cm3.txt",
                        "tas_2040a1b_nov_csiro_mk30.txt", "tas_2040a1b_nov_gfdl_cm20.txt",
                        "tas_2040a1b_nov_gfdl_cm21.txt", "tas_2040a1b_nov_miroc32_hires.txt",
                        "tas_2040a1b_nov_miub_echog.txt", "tas_2040a1b_nov_mpi_echam5.txt",
                        "tas_2040a1b_nov_mri_cgcm232.txt", "tas_2040a1b_nov_ncar_ccsm30.txt",
                        "tas_2040a1b_nov_ukmo_hadcm3.txt", "tas_2040a1b_nov_ukmo_hadgem1.txt",
                        "tas_2040a1b_oct_cccma_cgcm3.txt", "tas_2040a1b_oct_cnrm_cm3.txt",
                        "tas_2040a1b_oct_csiro_mk30.txt", "tas_2040a1b_oct_gfdl_cm20.txt",
                        "tas_2040a1b_oct_gfdl_cm21.txt", "tas_2040a1b_oct_miroc32_hires.txt",
                        "tas_2040a1b_oct_miub_echog.txt", "tas_2040a1b_oct_mpi_echam5.txt",
                        "tas_2040a1b_oct_mri_cgcm232.txt", "tas_2040a1b_oct_ncar_ccsm30.txt",
                        "tas_2040a1b_oct_ukmo_hadcm3.txt", "tas_2040a1b_oct_ukmo_hadgem1.txt",
                        "tas_2040a1b_sep_cccma_cgcm3.txt", "tas_2040a1b_sep_cnrm_cm3.txt",
                        "tas_2040a1b_sep_csiro_mk30.txt", "tas_2040a1b_sep_gfdl_cm20.txt",
                        "tas_2040a1b_sep_gfdl_cm21.txt", "tas_2040a1b_sep_miroc32_hires.txt",
                        "tas_2040a1b_sep_miub_echog.txt", "tas_2040a1b_sep_mpi_echam5.txt",
                        "tas_2040a1b_sep_mri_cgcm232.txt", "tas_2040a1b_sep_ncar_ccsm30.txt",
                        "tas_2040a1b_sep_ukmo_hadcm3.txt", "tas_2040a1b_sep_ukmo_hadgem1.txt",
                        "tas_2090a1b_apr_cccma_cgcm3.txt", "tas_2090a1b_apr_cnrm_cm3.txt",
                        "tas_2090a1b_apr_csiro_mk30.txt", "tas_2090a1b_apr_gfdl_cm20.txt",
                        "tas_2090a1b_apr_gfdl_cm21.txt", "tas_2090a1b_apr_miroc32_hires.txt",
                        "tas_2090a1b_apr_miub_echog.txt", "tas_2090a1b_apr_mpi_echam5.txt",
                        "tas_2090a1b_apr_mri_cgcm232.txt", "tas_2090a1b_apr_ncar_ccsm30.txt",
                        "tas_2090a1b_apr_ukmo_hadcm3.txt", "tas_2090a1b_apr_ukmo_hadgem1.txt",
                        "tas_2090a1b_aug_cccma_cgcm3.txt", "tas_2090a1b_aug_cnrm_cm3.txt",
                        "tas_2090a1b_aug_csiro_mk30.txt", "tas_2090a1b_aug_gfdl_cm20.txt",
                        "tas_2090a1b_aug_gfdl_cm21.txt", "tas_2090a1b_aug_miroc32_hires.txt",
                        "tas_2090a1b_aug_miub_echog.txt", "tas_2090a1b_aug_mpi_echam5.txt",
                        "tas_2090a1b_aug_mri_cgcm232.txt", "tas_2090a1b_aug_ncar_ccsm30.txt",
                        "tas_2090a1b_aug_ukmo_hadcm3.txt", "tas_2090a1b_aug_ukmo_hadgem1.txt",
                        "tas_2090a1b_dec_cccma_cgcm3.txt", "tas_2090a1b_dec_cnrm_cm3.txt",
                        "tas_2090a1b_dec_csiro_mk30.txt", "tas_2090a1b_dec_gfdl_cm20.txt",
                        "tas_2090a1b_dec_gfdl_cm21.txt", "tas_2090a1b_dec_miroc32_hires.txt",
                        "tas_2090a1b_dec_miub_echog.txt", "tas_2090a1b_dec_mpi_echam5.txt",
                        "tas_2090a1b_dec_mri_cgcm232.txt", "tas_2090a1b_dec_ncar_ccsm30.txt",
                        "tas_2090a1b_dec_ukmo_hadcm3.txt", "tas_2090a1b_dec_ukmo_hadgem1.txt",
                        "tas_2090a1b_feb_cccma_cgcm3.txt", "tas_2090a1b_feb_cnrm_cm3.txt",
                        "tas_2090a1b_feb_csiro_mk30.txt", "tas_2090a1b_feb_gfdl_cm20.txt",
                        "tas_2090a1b_feb_gfdl_cm21.txt", "tas_2090a1b_feb_miroc32_hires.txt",
                        "tas_2090a1b_feb_miub_echog.txt", "tas_2090a1b_feb_mpi_echam5.txt",
                        "tas_2090a1b_feb_mri_cgcm232.txt", "tas_2090a1b_feb_ncar_ccsm30.txt",
                        "tas_2090a1b_feb_ukmo_hadcm3.txt", "tas_2090a1b_feb_ukmo_hadgem1.txt",
                        "tas_2090a1b_jan_cccma_cgcm3.txt", "tas_2090a1b_jan_cnrm_cm3.txt",
                        "tas_2090a1b_jan_csiro_mk30.txt", "tas_2090a1b_jan_gfdl_cm20.txt",
                        "tas_2090a1b_jan_gfdl_cm21.txt", "tas_2090a1b_jan_miroc32_hires.txt",
                        "tas_2090a1b_jan_miub_echog.txt", "tas_2090a1b_jan_mpi_echam5.txt",
                        "tas_2090a1b_jan_mri_cgcm232.txt", "tas_2090a1b_jan_ncar_ccsm30.txt",
                        "tas_2090a1b_jan_ukmo_hadcm3.txt", "tas_2090a1b_jan_ukmo_hadgem1.txt",
                        "tas_2090a1b_jul_cccma_cgcm3.txt", "tas_2090a1b_jul_cnrm_cm3.txt",
                        "tas_2090a1b_jul_csiro_mk30.txt", "tas_2090a1b_jul_gfdl_cm20.txt",
                        "tas_2090a1b_jul_gfdl_cm21.txt", "tas_2090a1b_jul_miroc32_hires.txt",
                        "tas_2090a1b_jul_miub_echog.txt", "tas_2090a1b_jul_mpi_echam5.txt",
                        "tas_2090a1b_jul_mri_cgcm232.txt", "tas_2090a1b_jul_ncar_ccsm30.txt",
                        "tas_2090a1b_jul_ukmo_hadcm3.txt", "tas_2090a1b_jul_ukmo_hadgem1.txt",
                        "tas_2090a1b_jun_cccma_cgcm3.txt", "tas_2090a1b_jun_cnrm_cm3.txt",
                        "tas_2090a1b_jun_csiro_mk30.txt", "tas_2090a1b_jun_gfdl_cm20.txt",
                        "tas_2090a1b_jun_gfdl_cm21.txt", "tas_2090a1b_jun_miroc32_hires.txt",
                        "tas_2090a1b_jun_miub_echog.txt", "tas_2090a1b_jun_mpi_echam5.txt",
                        "tas_2090a1b_jun_mri_cgcm232.txt", "tas_2090a1b_jun_ncar_ccsm30.txt",
                        "tas_2090a1b_jun_ukmo_hadcm3.txt", "tas_2090a1b_jun_ukmo_hadgem1.txt",
                        "tas_2090a1b_mar_cccma_cgcm3.txt", "tas_2090a1b_mar_cnrm_cm3.txt",
                        "tas_2090a1b_mar_csiro_mk30.txt", "tas_2090a1b_mar_gfdl_cm20.txt",
                        "tas_2090a1b_mar_gfdl_cm21.txt", "tas_2090a1b_mar_miroc32_hires.txt",
                        "tas_2090a1b_mar_miub_echog.txt", "tas_2090a1b_mar_mpi_echam5.txt",
                        "tas_2090a1b_mar_mri_cgcm232.txt", "tas_2090a1b_mar_ncar_ccsm30.txt",
                        "tas_2090a1b_mar_ukmo_hadcm3.txt", "tas_2090a1b_mar_ukmo_hadgem1.txt",
                        "tas_2090a1b_may_cccma_cgcm3.txt", "tas_2090a1b_may_cnrm_cm3.txt",
                        "tas_2090a1b_may_csiro_mk30.txt", "tas_2090a1b_may_gfdl_cm20.txt",
                        "tas_2090a1b_may_gfdl_cm21.txt", "tas_2090a1b_may_miroc32_hires.txt",
                        "tas_2090a1b_may_miub_echog.txt", "tas_2090a1b_may_mpi_echam5.txt",
                        "tas_2090a1b_may_mri_cgcm232.txt", "tas_2090a1b_may_ncar_ccsm30.txt",
                        "tas_2090a1b_may_ukmo_hadcm3.txt", "tas_2090a1b_may_ukmo_hadgem1.txt",
                        "tas_2090a1b_nov_cccma_cgcm3.txt", "tas_2090a1b_nov_cnrm_cm3.txt",
                        "tas_2090a1b_nov_csiro_mk30.txt", "tas_2090a1b_nov_gfdl_cm20.txt",
                        "tas_2090a1b_nov_gfdl_cm21.txt", "tas_2090a1b_nov_miroc32_hires.txt",
                        "tas_2090a1b_nov_miub_echog.txt", "tas_2090a1b_nov_mpi_echam5.txt",
                        "tas_2090a1b_nov_mri_cgcm232.txt", "tas_2090a1b_nov_ncar_ccsm30.txt",
                        "tas_2090a1b_nov_ukmo_hadcm3.txt", "tas_2090a1b_nov_ukmo_hadgem1.txt",
                        "tas_2090a1b_oct_cccma_cgcm3.txt", "tas_2090a1b_oct_cnrm_cm3.txt",
                        "tas_2090a1b_oct_csiro_mk30.txt", "tas_2090a1b_oct_gfdl_cm20.txt",
                        "tas_2090a1b_oct_gfdl_cm21.txt", "tas_2090a1b_oct_miroc32_hires.txt",
                        "tas_2090a1b_oct_miub_echog.txt", "tas_2090a1b_oct_mpi_echam5.txt",
                        "tas_2090a1b_oct_mri_cgcm232.txt", "tas_2090a1b_oct_ncar_ccsm30.txt",
                        "tas_2090a1b_oct_ukmo_hadcm3.txt", "tas_2090a1b_oct_ukmo_hadgem1.txt",
                        "tas_2090a1b_sep_cccma_cgcm3.txt", "tas_2090a1b_sep_cnrm_cm3.txt",
                        "tas_2090a1b_sep_csiro_mk30.txt", "tas_2090a1b_sep_gfdl_cm20.txt",
                        "tas_2090a1b_sep_gfdl_cm21.txt", "tas_2090a1b_sep_miroc32_hires.txt",
                        "tas_2090a1b_sep_miub_echog.txt", "tas_2090a1b_sep_mpi_echam5.txt",
                        "tas_2090a1b_sep_mri_cgcm232.txt", "tas_2090a1b_sep_ncar_ccsm30.txt",
                        "tas_2090a1b_sep_ukmo_hadcm3.txt", "tas_2090a1b_sep_ukmo_hadgem1.txt"
)

knk.split <- strsplit(knk, "_")
knk.years <- as.factor(unlist(lapply(knk.split, "[", 2)))
knk.model <- lapply(strsplit(unlist(lapply(knk.split, "[", 5)),          "\\.<file:///\\.>"), "[", 1)
out1 <- mapply(function(x, y) {
                                    list(knk[grepl(pattern = x, x = knk) & grepl(pattern = paste("_", y, sep = ""), x = knk) ])
                        }, knk.years, knk.model)

out.names <- mapply(paste, knk.years, knk.model, sep = "_")
names(out1) <- out.names


Cheers,
Roman



On Sat, Mar 3, 2012 at 2:36 PM, Roman Luštrik <roman.lustrik@gmail.com<mailto:roman.lustrik@gmail.com>> wrote:
Yes. I'm working on it. The solution is not going to be fancy using regular expressions, although that would be very elegant. I'm using strsplit. Hang on.

Cheers,
Roman



On Sat, Mar 3, 2012 at 1:48 PM, Kanika Jhunjhnuwala <JhunjhnuwalaK@landcareresearch.co.nz<mailto:JhunjhnuwalaK@landcareresearch.co.nz>> wrote:
There are like 288 files that I eventually need. Im listing all the filenames without the path. Is that what you want?

Thanks
Kanika



c("tas_2040a1b_apr_cccma_cgcm3.txt", "tas_2040a1b_apr_cnrm_cm3.txt",
"tas_2040a1b_apr_csiro_mk30.txt", "tas_2040a1b_apr_gfdl_cm20.txt",
"tas_2040a1b_apr_gfdl_cm21.txt", "tas_2040a1b_apr_miroc32_hires.txt",
"tas_2040a1b_apr_miub_echog.txt", "tas_2040a1b_apr_mpi_echam5.txt",
"tas_2040a1b_apr_mri_cgcm232.txt", "tas_2040a1b_apr_ncar_ccsm30.txt",
"tas_2040a1b_apr_ukmo_hadcm3.txt", "tas_2040a1b_apr_ukmo_hadgem1.txt",
"tas_2040a1b_aug_cccma_cgcm3.txt", "tas_2040a1b_aug_cnrm_cm3.txt",
"tas_2040a1b_aug_csiro_mk30.txt", "tas_2040a1b_aug_gfdl_cm20.txt",
"tas_2040a1b_aug_gfdl_cm21.txt", "tas_2040a1b_aug_miroc32_hires.txt",
"tas_2040a1b_aug_miub_echog.txt", "tas_2040a1b_aug_mpi_echam5.txt",
"tas_2040a1b_aug_mri_cgcm232.txt", "tas_2040a1b_aug_ncar_ccsm30.txt",
"tas_2040a1b_aug_ukmo_hadcm3.txt", "tas_2040a1b_aug_ukmo_hadgem1.txt",
"tas_2040a1b_dec_cccma_cgcm3.txt", "tas_2040a1b_dec_cnrm_cm3.txt",
"tas_2040a1b_dec_csiro_mk30.txt", "tas_2040a1b_dec_gfdl_cm20.txt",
"tas_2040a1b_dec_gfdl_cm21.txt", "tas_2040a1b_dec_miroc32_hires.txt",
"tas_2040a1b_dec_miub_echog.txt", "tas_2040a1b_dec_mpi_echam5.txt",
"tas_2040a1b_dec_mri_cgcm232.txt", "tas_2040a1b_dec_ncar_ccsm30.txt",
"tas_2040a1b_dec_ukmo_hadcm3.txt", "tas_2040a1b_dec_ukmo_hadgem1.txt",
"tas_2040a1b_feb_cccma_cgcm3.txt", "tas_2040a1b_feb_cnrm_cm3.txt",
"tas_2040a1b_feb_csiro_mk30.txt", "tas_2040a1b_feb_gfdl_cm20.txt",
"tas_2040a1b_feb_gfdl_cm21.txt", "tas_2040a1b_feb_miroc32_hires.txt",
"tas_2040a1b_feb_miub_echog.txt", "tas_2040a1b_feb_mpi_echam5.txt",
"tas_2040a1b_feb_mri_cgcm232.txt", "tas_2040a1b_feb_ncar_ccsm30.txt",
"tas_2040a1b_feb_ukmo_hadcm3.txt", "tas_2040a1b_feb_ukmo_hadgem1.txt",
"tas_2040a1b_jan_cccma_cgcm3.txt", "tas_2040a1b_jan_cnrm_cm3.txt",
"tas_2040a1b_jan_csiro_mk30.txt", "tas_2040a1b_jan_gfdl_cm20.txt",
"tas_2040a1b_jan_gfdl_cm21.txt", "tas_2040a1b_jan_miroc32_hires.txt",
"tas_2040a1b_jan_miub_echog.txt", "tas_2040a1b_jan_mpi_echam5.txt",
"tas_2040a1b_jan_mri_cgcm232.txt", "tas_2040a1b_jan_ncar_ccsm30.txt",
"tas_2040a1b_jan_ukmo_hadcm3.txt", "tas_2040a1b_jan_ukmo_hadgem1.txt",
"tas_2040a1b_jul_cccma_cgcm3.txt", "tas_2040a1b_jul_cnrm_cm3.txt",
"tas_2040a1b_jul_csiro_mk30.txt", "tas_2040a1b_jul_gfdl_cm20.txt",
"tas_2040a1b_jul_gfdl_cm21.txt", "tas_2040a1b_jul_miroc32_hires.txt",
"tas_2040a1b_jul_miub_echog.txt", "tas_2040a1b_jul_mpi_echam5.txt",
"tas_2040a1b_jul_mri_cgcm232.txt", "tas_2040a1b_jul_ncar_ccsm30.txt",
"tas_2040a1b_jul_ukmo_hadcm3.txt", "tas_2040a1b_jul_ukmo_hadgem1.txt",
"tas_2040a1b_jun_cccma_cgcm3.txt", "tas_2040a1b_jun_cnrm_cm3.txt",
"tas_2040a1b_jun_csiro_mk30.txt", "tas_2040a1b_jun_gfdl_cm20.txt",
"tas_2040a1b_jun_gfdl_cm21.txt", "tas_2040a1b_jun_miroc32_hires.txt",
"tas_2040a1b_jun_miub_echog.txt", "tas_2040a1b_jun_mpi_echam5.txt",
"tas_2040a1b_jun_mri_cgcm232.txt", "tas_2040a1b_jun_ncar_ccsm30.txt",
"tas_2040a1b_jun_ukmo_hadcm3.txt", "tas_2040a1b_jun_ukmo_hadgem1.txt",
"tas_2040a1b_mar_cccma_cgcm3.txt", "tas_2040a1b_mar_cnrm_cm3.txt",
"tas_2040a1b_mar_csiro_mk30.txt", "tas_2040a1b_mar_gfdl_cm20.txt",
"tas_2040a1b_mar_gfdl_cm21.txt", "tas_2040a1b_mar_miroc32_hires.txt",
"tas_2040a1b_mar_miub_echog.txt", "tas_2040a1b_mar_mpi_echam5.txt",
"tas_2040a1b_mar_mri_cgcm232.txt", "tas_2040a1b_mar_ncar_ccsm30.txt",
"tas_2040a1b_mar_ukmo_hadcm3.txt", "tas_2040a1b_mar_ukmo_hadgem1.txt",
"tas_2040a1b_may_cccma_cgcm3.txt", "tas_2040a1b_may_cnrm_cm3.txt",
"tas_2040a1b_may_csiro_mk30.txt", "tas_2040a1b_may_gfdl_cm20.txt",
"tas_2040a1b_may_gfdl_cm21.txt", "tas_2040a1b_may_miroc32_hires.txt",
"tas_2040a1b_may_miub_echog.txt", "tas_2040a1b_may_mpi_echam5.txt",
"tas_2040a1b_may_mri_cgcm232.txt", "tas_2040a1b_may_ncar_ccsm30.txt",
"tas_2040a1b_may_ukmo_hadcm3.txt", "tas_2040a1b_may_ukmo_hadgem1.txt",
"tas_2040a1b_nov_cccma_cgcm3.txt", "tas_2040a1b_nov_cnrm_cm3.txt",
"tas_2040a1b_nov_csiro_mk30.txt", "tas_2040a1b_nov_gfdl_cm20.txt",
"tas_2040a1b_nov_gfdl_cm21.txt", "tas_2040a1b_nov_miroc32_hires.txt",
"tas_2040a1b_nov_miub_echog.txt", "tas_2040a1b_nov_mpi_echam5.txt",
"tas_2040a1b_nov_mri_cgcm232.txt", "tas_2040a1b_nov_ncar_ccsm30.txt",
"tas_2040a1b_nov_ukmo_hadcm3.txt", "tas_2040a1b_nov_ukmo_hadgem1.txt",
"tas_2040a1b_oct_cccma_cgcm3.txt", "tas_2040a1b_oct_cnrm_cm3.txt",
"tas_2040a1b_oct_csiro_mk30.txt", "tas_2040a1b_oct_gfdl_cm20.txt",
"tas_2040a1b_oct_gfdl_cm21.txt", "tas_2040a1b_oct_miroc32_hires.txt",
"tas_2040a1b_oct_miub_echog.txt", "tas_2040a1b_oct_mpi_echam5.txt",
"tas_2040a1b_oct_mri_cgcm232.txt", "tas_2040a1b_oct_ncar_ccsm30.txt",
"tas_2040a1b_oct_ukmo_hadcm3.txt", "tas_2040a1b_oct_ukmo_hadgem1.txt",
"tas_2040a1b_sep_cccma_cgcm3.txt", "tas_2040a1b_sep_cnrm_cm3.txt",
"tas_2040a1b_sep_csiro_mk30.txt", "tas_2040a1b_sep_gfdl_cm20.txt",
"tas_2040a1b_sep_gfdl_cm21.txt", "tas_2040a1b_sep_miroc32_hires.txt",
"tas_2040a1b_sep_miub_echog.txt", "tas_2040a1b_sep_mpi_echam5.txt",
"tas_2040a1b_sep_mri_cgcm232.txt", "tas_2040a1b_sep_ncar_ccsm30.txt",
"tas_2040a1b_sep_ukmo_hadcm3.txt", "tas_2040a1b_sep_ukmo_hadgem1.txt",
"tas_2090a1b_apr_cccma_cgcm3.txt", "tas_2090a1b_apr_cnrm_cm3.txt",
"tas_2090a1b_apr_csiro_mk30.txt", "tas_2090a1b_apr_gfdl_cm20.txt",
"tas_2090a1b_apr_gfdl_cm21.txt", "tas_2090a1b_apr_miroc32_hires.txt",
"tas_2090a1b_apr_miub_echog.txt", "tas_2090a1b_apr_mpi_echam5.txt",
"tas_2090a1b_apr_mri_cgcm232.txt", "tas_2090a1b_apr_ncar_ccsm30.txt",
"tas_2090a1b_apr_ukmo_hadcm3.txt", "tas_2090a1b_apr_ukmo_hadgem1.txt",
"tas_2090a1b_aug_cccma_cgcm3.txt", "tas_2090a1b_aug_cnrm_cm3.txt",
"tas_2090a1b_aug_csiro_mk30.txt", "tas_2090a1b_aug_gfdl_cm20.txt",
"tas_2090a1b_aug_gfdl_cm21.txt", "tas_2090a1b_aug_miroc32_hires.txt",
"tas_2090a1b_aug_miub_echog.txt", "tas_2090a1b_aug_mpi_echam5.txt",
"tas_2090a1b_aug_mri_cgcm232.txt", "tas_2090a1b_aug_ncar_ccsm30.txt",
"tas_2090a1b_aug_ukmo_hadcm3.txt", "tas_2090a1b_aug_ukmo_hadgem1.txt",
"tas_2090a1b_dec_cccma_cgcm3.txt", "tas_2090a1b_dec_cnrm_cm3.txt",
"tas_2090a1b_dec_csiro_mk30.txt", "tas_2090a1b_dec_gfdl_cm20.txt",
"tas_2090a1b_dec_gfdl_cm21.txt", "tas_2090a1b_dec_miroc32_hires.txt",
"tas_2090a1b_dec_miub_echog.txt", "tas_2090a1b_dec_mpi_echam5.txt",
"tas_2090a1b_dec_mri_cgcm232.txt", "tas_2090a1b_dec_ncar_ccsm30.txt",
"tas_2090a1b_dec_ukmo_hadcm3.txt", "tas_2090a1b_dec_ukmo_hadgem1.txt",
"tas_2090a1b_feb_cccma_cgcm3.txt", "tas_2090a1b_feb_cnrm_cm3.txt",
"tas_2090a1b_feb_csiro_mk30.txt", "tas_2090a1b_feb_gfdl_cm20.txt",
"tas_2090a1b_feb_gfdl_cm21.txt", "tas_2090a1b_feb_miroc32_hires.txt",
"tas_2090a1b_feb_miub_echog.txt", "tas_2090a1b_feb_mpi_echam5.txt",
"tas_2090a1b_feb_mri_cgcm232.txt", "tas_2090a1b_feb_ncar_ccsm30.txt",
"tas_2090a1b_feb_ukmo_hadcm3.txt", "tas_2090a1b_feb_ukmo_hadgem1.txt",
"tas_2090a1b_jan_cccma_cgcm3.txt", "tas_2090a1b_jan_cnrm_cm3.txt",
"tas_2090a1b_jan_csiro_mk30.txt", "tas_2090a1b_jan_gfdl_cm20.txt",
"tas_2090a1b_jan_gfdl_cm21.txt", "tas_2090a1b_jan_miroc32_hires.txt",
"tas_2090a1b_jan_miub_echog.txt", "tas_2090a1b_jan_mpi_echam5.txt",
"tas_2090a1b_jan_mri_cgcm232.txt", "tas_2090a1b_jan_ncar_ccsm30.txt",
"tas_2090a1b_jan_ukmo_hadcm3.txt", "tas_2090a1b_jan_ukmo_hadgem1.txt",
"tas_2090a1b_jul_cccma_cgcm3.txt", "tas_2090a1b_jul_cnrm_cm3.txt",
"tas_2090a1b_jul_csiro_mk30.txt", "tas_2090a1b_jul_gfdl_cm20.txt",
"tas_2090a1b_jul_gfdl_cm21.txt", "tas_2090a1b_jul_miroc32_hires.txt",
"tas_2090a1b_jul_miub_echog.txt", "tas_2090a1b_jul_mpi_echam5.txt",
"tas_2090a1b_jul_mri_cgcm232.txt", "tas_2090a1b_jul_ncar_ccsm30.txt",
"tas_2090a1b_jul_ukmo_hadcm3.txt", "tas_2090a1b_jul_ukmo_hadgem1.txt",
"tas_2090a1b_jun_cccma_cgcm3.txt", "tas_2090a1b_jun_cnrm_cm3.txt",
"tas_2090a1b_jun_csiro_mk30.txt", "tas_2090a1b_jun_gfdl_cm20.txt",
"tas_2090a1b_jun_gfdl_cm21.txt", "tas_2090a1b_jun_miroc32_hires.txt",
"tas_2090a1b_jun_miub_echog.txt", "tas_2090a1b_jun_mpi_echam5.txt",
"tas_2090a1b_jun_mri_cgcm232.txt", "tas_2090a1b_jun_ncar_ccsm30.txt",
"tas_2090a1b_jun_ukmo_hadcm3.txt", "tas_2090a1b_jun_ukmo_hadgem1.txt",
"tas_2090a1b_mar_cccma_cgcm3.txt", "tas_2090a1b_mar_cnrm_cm3.txt",
"tas_2090a1b_mar_csiro_mk30.txt", "tas_2090a1b_mar_gfdl_cm20.txt",
"tas_2090a1b_mar_gfdl_cm21.txt", "tas_2090a1b_mar_miroc32_hires.txt",
"tas_2090a1b_mar_miub_echog.txt", "tas_2090a1b_mar_mpi_echam5.txt",
"tas_2090a1b_mar_mri_cgcm232.txt", "tas_2090a1b_mar_ncar_ccsm30.txt",
"tas_2090a1b_mar_ukmo_hadcm3.txt", "tas_2090a1b_mar_ukmo_hadgem1.txt",
"tas_2090a1b_may_cccma_cgcm3.txt", "tas_2090a1b_may_cnrm_cm3.txt",
"tas_2090a1b_may_csiro_mk30.txt", "tas_2090a1b_may_gfdl_cm20.txt",
"tas_2090a1b_may_gfdl_cm21.txt", "tas_2090a1b_may_miroc32_hires.txt",
"tas_2090a1b_may_miub_echog.txt", "tas_2090a1b_may_mpi_echam5.txt",
"tas_2090a1b_may_mri_cgcm232.txt", "tas_2090a1b_may_ncar_ccsm30.txt",
"tas_2090a1b_may_ukmo_hadcm3.txt", "tas_2090a1b_may_ukmo_hadgem1.txt",
"tas_2090a1b_nov_cccma_cgcm3.txt", "tas_2090a1b_nov_cnrm_cm3.txt",
"tas_2090a1b_nov_csiro_mk30.txt", "tas_2090a1b_nov_gfdl_cm20.txt",
"tas_2090a1b_nov_gfdl_cm21.txt", "tas_2090a1b_nov_miroc32_hires.txt",
"tas_2090a1b_nov_miub_echog.txt", "tas_2090a1b_nov_mpi_echam5.txt",
"tas_2090a1b_nov_mri_cgcm232.txt", "tas_2090a1b_nov_ncar_ccsm30.txt",
"tas_2090a1b_nov_ukmo_hadcm3.txt", "tas_2090a1b_nov_ukmo_hadgem1.txt",
"tas_2090a1b_oct_cccma_cgcm3.txt", "tas_2090a1b_oct_cnrm_cm3.txt",
"tas_2090a1b_oct_csiro_mk30.txt", "tas_2090a1b_oct_gfdl_cm20.txt",
"tas_2090a1b_oct_gfdl_cm21.txt", "tas_2090a1b_oct_miroc32_hires.txt",
"tas_2090a1b_oct_miub_echog.txt", "tas_2090a1b_oct_mpi_echam5.txt",
"tas_2090a1b_oct_mri_cgcm232.txt", "tas_2090a1b_oct_ncar_ccsm30.txt",
"tas_2090a1b_oct_ukmo_hadcm3.txt", "tas_2090a1b_oct_ukmo_hadgem1.txt",
"tas_2090a1b_sep_cccma_cgcm3.txt", "tas_2090a1b_sep_cnrm_cm3.txt",
"tas_2090a1b_sep_csiro_mk30.txt", "tas_2090a1b_sep_gfdl_cm20.txt",
"tas_2090a1b_sep_gfdl_cm21.txt", "tas_2090a1b_sep_miroc32_hires.txt",
"tas_2090a1b_sep_miub_echog.txt", "tas_2090a1b_sep_mpi_echam5.txt",
"tas_2090a1b_sep_mri_cgcm232.txt", "tas_2090a1b_sep_ncar_ccsm30.txt",
"tas_2090a1b_sep_ukmo_hadcm3.txt", "tas_2090a1b_sep_ukmo_hadgem1.txt"
)

From: romunov@gmail.com<mailto:romunov@gmail.com> [mailto:romunov@gmail.com<mailto:romunov@gmail.com>] On Behalf Of Roman Luštrik
Sent: Sunday, 4 March 2012 1:26 a.m.
To: Kanika Jhunjhnuwala
Subject: Re: [R-sig-Geo] looping over files

Can you send your list of files?


On Sat, Mar 3, 2012 at 12:42 PM, Kanika Jhunjhnuwala <JhunjhnuwalaK@landcareresearch.co.nz<mailto:JhunjhnuwalaK@landcareresearch.co.nz>> wrote:
Hi

I have been trying to loop over lists of files while specifying variables. I am not getting anywhere.

There are basically 3 variables month, year and modelname. My files have the format "tas_",year,"_" ,month,"_", modelname,".txt". I basically want to loop through all the models and put all the data pertaining to that model and year in one list while also naming the list as modelname,"_",year. So basically each list will be 12 long with the files from each month (jan through dec). I have tried using list.files but I do not think you can specify variables in the pattern.

Files<- list.files(path="eg/", pattern="tas_",year,"_" ,month,"_", modelname,".txt", full.names=TRUE)

Does anyone know how to do this? I have 12 models and 2 different years and I want to get all the months of a single year and single model in a single list of files (ie 12 files in a list) with each list specified by the modelname and year.

Thanks

Kanika


________________________________
Please consider the environment before printing this email
Warning: This electronic message together with any attachments is confidential. If you receive it in error: (i) you must not read, use, disclose, copy or retain it; (ii) please contact the sender immediately by reply email and then delete the emails.
The views expressed in this email may not be those of Landcare Research New Zealand Limited. http://www.landcareresearch.co.nz

       [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org<mailto:R-sig-Geo@r-project.org>
https://stat.ethz.ch/mailman/listinfo/r-sig-geo



--
In God we trust, all others bring data.

________________________________
Please consider the environment before printing this email
Warning: This electronic message together with any attachments is confidential. If you receive it in error: (i) you must not read, use, disclose, copy or retain it; (ii) please contact the sender immediately by reply email and then delete the emails.
The views expressed in this email may not be those of Landcare Research New Zealand Limited. http://www.landcareresearch.co.nz



--
In God we trust, all others bring data.



--
In God we trust, all others bring data.

________________________________
Please consider the environment before printing this email
Warning: This electronic message together with any attachments is confidential. If you receive it in error: (i) you must not read, use, disclose, copy or retain it; (ii) please contact the sender immediately by reply email and then delete the emails.
The views expressed in this email may not be those of Landcare Research New Zealand Limited. http://www.landcareresearch.co.nz

	[[alternative HTML version deleted]]

