I am a newbie with R. I have 6 different data frames (U, V, W, X, Y, Z), coming from different CSV files, each of them has the same columns (Surname, Name, Winter, Spring, Summer), and I would like to create a new data frame containing the 5 rows and a sixth row which indicates one of the letters (U, V, ...) where the original data comes from. I have tried with the following code:
U <- read.csv(file = "U", header = T)
V <- read.csv(file = "V", header = T)
W <- read.csv(file = "W", header = T)
X <- read.csv(file = "X", header = T)
Y <- read.csv(file = "Y", header = T)
Z <- read.csv(file = "Z", header = T)
U['class'] <- rep("U")
V['class'] <- rep("V")
W['class'] <- rep("W")
X['class'] <- rep("X")
Y['class'] <- rep("Y")
Z['class'] <- rep("Z")
students <- rbind(U, V, W, X, Y, Z)
I would really need to use a loop, so that I can in future go from A to Z. I would like to do something like this, which is totally nonsense.
for(class.name in list(U, V, W, X, Y, Z)){
class.name['class'] <- rep('class')
}
Is there a reasonable way to do it?
Thank you
Edited
To clarify my question, the idea is that I have 6 different stations collecting raw data and giving me 6 different data frames. I want to merge them together, maintaining the information of from which station the raw data comes from.
Possible incomplete solution Following @MrFlick's advice, I have managed to put everything in one list as follows
classes <- c('U', 'V', 'W', 'X', 'W', 'Z')
my.files <- paste(classes,".csv",sep="")
year.eight <- lapply(my.files, read.csv, header = T)
name(year.eight) <- classes
However, the final outcome should be one single data frame with a further column to indicate which class are the students in. Can someone help me with this, please?