0

I have a list of data frames that I'am relying to maintain the same column name, but when I export the names are personalized based on their name

for example I have three tables

c("Table1",Table2","Table3")

Each table has the same columns

c("Col1","Col2","Col3","Col4")

When I open the file Table1 it has personalized columns such as

c("Table1.Col1","Table1.Col2","Table1.Col3","Table1.Col4")

I want all .csv to maintain their proper column name and not get modified based on their dataframe name.

I'm using

for(i in 1:length(df)){
write.csv(df[i], paste0(df,names(list)[i], ".csv"), row.names = FALSE,na="")
}
user35131
  • 1,105
  • 6
  • 18
  • Do you mind sharing a [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including `Table1`, `Table2` (at least `dput(head())` and `Pre.list`? – Martin Gal Dec 22 '22 at 22:56
  • 1
    If `Pre.list` is indeed a list, you could try using `Pre.list[[i]]` instead of `Pre.list[i]`. `Pre.list[[i]]` returns the data.frame, `Prelist[i]` the element of the list containing a data.frame. This creates confusing column names while writing out via `write.csv`. – Martin Gal Dec 22 '22 at 23:02
  • 1
    Check out https://stackoverflow.com/questions/1169456/the-difference-between-bracket-and-double-bracket-for-accessing-the-el – Martin Gal Dec 22 '22 at 23:09

0 Answers0