[R] How to aggregate values in corresponding dataframes
lily li
choco|d12 @end|ng |rom gm@||@com
Mon Mar 25 09:30:11 CET 2019
Hi R users,
I have multiple dataframes in a directory, and with the same postfix
".txt". Each dataframe is a gridded file with just values, but each value
represents one grid cell. There are many years, and each year has 12
months, so there are many such files. For each year, I want to read the
corresponding year's files and add the values of the dataframes, but I
don't know how to do that. For example, the file names are
1990_file01.txt
1990_file02.txt
...
1990_file12.txt
1991_file01.txt
...
1991_file12.txt
...
And my code is like this:
f1990 = list.files("~/directory", pattern = "^1990(.*).txt$")
for(i in 1:length(f1990)){
r1990 = read.table(paste('~/directory',f1990[i],sep='/'),head=F)
}
Could you provide some help on this? Thanks very much.
[[alternative HTML version deleted]]
More information about the R-help
mailing list