I would like to loop through individual data frames (not in a list) and append a column to each df so that the appended column is a copy of column one in the original df.
For df x:
> x
V1 V2 V3
1 1 2 3
2 1 2 3
3 1 2 2
4 1 2 2
5 1 1 1
Desired output would be:
> x
V1 V2 V3 newCol
1 1 2 3 1
2 1 2 3 1
3 1 2 2 1
4 1 2 2 1
5 1 1 1 1
I tried using this loop:
filenames <- names(which(sapply(.GlobalEnv, is.data.frame)))
for(x in seq_along(filenames)){
filenames[x]$newCol <- x[,1]
}
but error occurs:
Error in x[, 1] : incorrect number of dimensions