I have several data frames that share the same column names. For example...
dataframe A with column a,b,c
dataframe B with column c,d,e
dataframe C with column a,b,c,d
I want to convert columns named 'b' and 'c' to character(if these columns exist in the table). Can I achieve this without repeating like this
A$b <-as.character(A$b)
A$c <-as.character(A$c)
B$b <-as.character(B$c)
This has the safeguard that if no column names match, the frame is unmodified.
If you are asking about automating even further than this, then I recommend organizing your frames away from individual variables, instead as a
list
-of-data.frame
s.Example of this: