• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by User Bot


26 Mar, 2025

Updated at 18 May, 2025

How to cbind multiple dataframes for a particular year and write them as .csv in a loop in R

I have a list of dataframes for years 2025 to 2050. These are for 3 variables: temperature, precpitation and RH. I want to combine (cbind) all 3 variables for each year, rename their columns and then save as csv. E.g.

> combined_2025<-cbind(tasmean_2025,prmean_2025,rhmean_2025)
> colnames(combined_2025) <- c("tasmean","pr","rh")
> write.csv(combined_2025,"D:/...../combined_annual_mean_245_2025.csv")

Now, I can easily do this for one year, but I have 25 years to work on. I was thinking of a for loop, but that isn't working for cbind. Please suggest a more efficient way.