I'm just learning R. I have 300 different files containing rainfall data. I want to create a function that takes a range of values (i.e., 20-40). I will then read csv files named "020.csv", "021.csv", "022.csv" etc. up to "040.csv".
Each of these files has a variable named "rainfall". I want to open each csv file, extract the "rainfall" values and store (append) them to some sort of object, like a data frame (maybe something else is better?). So, when I'm done, I'll have a data frame or list with a single column containing rainfall data from all processed files.
This is what I have...
rainfallValues <- function(id = 1:300) { df = data.frame() # Read anywhere from 1 to 300 files for(i in id) { # Form a file name fileName <- sprintf("%03d.csv",i) # Read the csv file which has four variables (columns). I'm interested in # a variable named "rainfall". x <- read.csv(fileName,header=T) # This is where I am stuck. I know how to exact the "rainfall" variable values from # x, I just don't know how to append them to my data frame. } }