Saturday, 10 August 2013

I have multiple dataframes under one name and I need to create a new column in each one by combining two of the other columns?

I have multiple dataframes under one name and I need to create a new
column in each one by combining two of the other columns?

I am trying to take in a bunch of csv files of a specific name form
(dates) as dataframes and then combine data from two of the columns into a
new column for each of the files. There are over 100 of these files so I
do not want to manually create a new column for each file. Is there any
way to do this? Here is an example:
a b a b a b c a b c
x 2 3 x 3 1 --> x 2 3 23 x 3 1 31
And here is my current code:
f <- list.files(pattern="201\\d{5}\\.csv")
mydata <- sapply(f, read.csv, simplify=FALSE)
mydata$c <- paste(mydata$a,mydata$b)

No comments:

Post a Comment