-2
我有一个文件列表,并且我编写了一个函数来处理每个文件并返回两列(“名称”和“值”)。将多个文件合并成一个数据框并将文件名分配给每个文件名
file_list <- list.files(pattern=".txt")
sample_name <- sub (".*?lvl.(.*?).txt","\\1",file_list)
for (i in 1:length(file_list)){
x<- cleanMyData(file_list[i]) # this function returns a two column data
#then I want to merge all these processed data into one dataframe. Merge all "value" column based on the "name" column
# at the same time I want to put the file name in the corresponding column name. I already process the file name and put them into sample_name
}
更清楚,这是我的,例如处理数据:
file: apple.txt
name value
A 12
B 13
C 14
file: pear.txt
name value
A 15
B 14
C 20
D 21
期望输出:
Apple Pear
A 12 15
B 13 14
C 14 20
你可能只是'绑定'两个数据帧,但假设这些行排列完全正确。另一种选择是将'name'列上的两个数据框'合并()'。 –