Hello,

Try the following.

Data <- lapply(sprintf('file/%4i', 2000:2003), readLines)


This will give you a list with 4 elements, each of which is the contents of each file.

Hope this helps,

Rui Barradas

Em 17-02-2015 18:15, Alexandra Catena escreveu:
Hi,

I need help with a for loop and printing data.  I want to loop through a
few years and print the data from each year stacked on top of each other.
For example,

for (i in 2000:2003){
#script for downloading each year
Data = readLines(sprintf('file/%4i,i))
}

It only prints out the data from the last year.  Also, I tried

Data[i] =  readLines(sprintf('file/%4i,i))

but it says:

"number of items to replace is not a multiple of replacement length"

How do I get it to not replace each year of data? I have R version 2.15.1

Thanks,
Alexandra

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.


______________________________________________
R-help@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.

Reply via email to