I have 19 CSV files in a folder. each CSV file has 6 columns (Date,temperature,RH, Dewpt, Host, EOF). I want to merge all of the 19 files into a single data frame using Rstudio. For this, I need the new CSV files to be added as new columns. In another word, when the second file is merged with the first one, I want to see 11 columns(I just need one Date for all the cases), and when 3 files are merged I want to see 16 columns and so on. how can I do that? Also in the first cell of each file, there is a serial number for each CSV file. I want to add them as ID of each csv file as you can see in the attached pictures. I really appreciate your help. Thank you
You'll need to make a few adjustments:
library(tidyverse)
csv_files <- list.files("my_directory", pattern = ".csv", full.names = TRUE) # edit "my_directory"
combined_long <-
map_dfr(
csv_files,
read_csv,
col_names = c("datetime", "temp", "rh", "dp", "hc", "eof") # cleaned column names
.id = "file_name"
)
# change the file names to something short before running the next chunk
combined_wide <-
pivot_wider(
combined_long,
names_from = file_name,
values_from = c(temp, rh, dp, hc, eof)
)
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.