[R] reading in multiple data sets in 2 loops
Marc Girondot
marc_grt at yahoo.fr
Sun Feb 7 14:51:06 CET 2016
Try this:
# install package HelpersMG from CRAN including dependencies
install.packages("HelpersMG")
# Update to the lastest version
install.packages("http://www.ese.u-psud.fr/epc/conservation/CRAN/HelpersMG.tar.gz",
repos=NULL, type="source")
# Use the function read_folder()
library("HelpersMG")
content_as_list <- read_folder(folder =
"C:/Research3/simulation1/second_gen", wildcard = "*.csv",
read = read.csv)
I have created this function because I had exactely the same poblem that
you described !
Sincerely,
Marc
Le 06/02/2016 06:53, Reka Howard a écrit :
> Hello,
> I have over 1000 csv data sets I need to read into R, so I want to read
> them in using a loop. The data sets are named as
> pheno_1000ind_4000m_add_h70_prog_1_2.csv,
> pheno_1000ind_4000m_add_h70_prog_1_3.csv, ... so I need 2 loops (for the
> last 2 numbers in the names). What I would like to do is the following:
>
> setwd("C:/Research3/simulation1/second_gen")
> d1<-read.csv("pheno_1000ind_4000m_add_h70_prog_1_2.csv")
> d2<-read.csv("pheno_1000ind_4000m_add_h70_prog_1_3.csv")
> d3<-read.csv("pheno_1000ind_4000m_add_h70_prog_2_3.csv")
> .
> .
> .
>
> I am wondering how I can accomplish this with a loop. Any suggestion is
> appreciated!
> I tried the following but it does not work:
>
> data <- lapply(
> paste(("C:/Research3/simulation1/second_gen/pheno_1000ind_4000m_add_h70_prog_",[1:2],"_",[2:3],".csv",sep=''),
> read.csv, header=TRUE, sep=',' )
> names(data) <- paste("d", LETTERS[1:3], sep='')
>
> Thanks!
> Reka
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>
More information about the R-help
mailing list