[R] need held to build a loop for reading multiple datasets

Rui Barradas ruipbarradas at sapo.pt
Wed Aug 7 21:28:33 CEST 2013


Hello,

Also note that the index to datalist should be i + 1, 0 is not an 
allowed index number.


datalist[[i + 1]] <- read.table(...)

Hope this helps,

Rui Barradas

Em 07-08-2013 20:10, David Winsemius escreveu:
>
> On Aug 7, 2013, at 11:31 AM, Philipp Rath wrote:
>
>> Hello r-community,
>>
>> my name is philipp and i´m studying economics at the university of bonn.
>> I´m writing a paper about an experimental entry game and need help to write a for loop.
>>
>> for (i in 0:7) {
>>
>> data <- read.table("~/Uni/SoSe 13/Bachelorarbeit/entryGameAnalysis/analysis/data/23.04.13...10H/GROUP0/0/history.txt", sep="\t" , header=TRUE, blank.lines.skip=TRUE, strip.white = TRUE)
>> data[5]
>> }
>>
>> the goal is to read column 5 of the history.txt for GROUP0/0, GROUP0/1,…..GROUP0/7.
>>
>
> Something along these lines (and do note that your current arrangement would overwrite the previous file with each iteration and executing data[5] would have done nothing, since no assignment was made):
>
> datalist<-list()
> for (i in 0:7) {
>
> datalist[[i]] <- read.table(file=paste0("~/Uni/SoSe 13/Bachelorarbeit/entryGameAnalysis/analysis/data/23.04.13...10H/GROUP0/",i,"/history.txt"), sep="\t" , header=TRUE, blank.lines.skip=TRUE, strip.white = TRUE, colClasses=c(rep(NULL,4), "character",rep(NULL,1000))
>
> }
>
> Using colClasses to extract only the 5th column.
>



More information about the R-help mailing list