Я работаю с несколькими CSV-файлами в длинном формате. Каждый файл имеет разное количество столбцов, но одинаковое количество строк. Я пытался прочитать все файлы и объединил их в один df, но я не смог этого сделать. Пока что я использую этот код для чтения каждого файла по отдельности:
try <- read.table('input/SMPS/new_format/COALA_SMPS_20200218.txt', #set the file to read
sep = ',', #separator
header = F, # do not read the header
skip = 17, # skip 17 firdt lines of information
fill = T) %>% #fill all empty spaces in the df
t()%>% #transpose the data
data.frame()%>% #make it a df
select(1:196) #select the useful data
Я планировал использовать нечто похожее на этот код, но я не знаю, где включить функцию транспонирования, чтобы он работал.
smps_files_new <- list.files(pattern = '*.txt',path = 'input/SMPS/new_format/')#Change the path where the files are located
myfiles <-do.call("rbind", ##Apply the bind to the files
lapply(smps_files_new, ##call the list
function(x) ##apply the next function
read.csv(paste("input/SMPS/new_format/", x, sep=''),sep = ',', #separator
header = F, # do not read the header
skip = 17, # skip 17 first lines of information
stringsAsFactors = F,
fill = T))) ##