我有一个包含28个FCS文件(来自流式细胞仪的原始数据)的目录。我正在将'flowFrame'对象的列表转换为数据帧的列表,并且我想在每个数据帧中创建一个引用文件名的列。
library(flowCore)
list = list.files(pattern = "*.fcs") # create a list with all of the files
list = lapply(list, read.FCS) # import all of the FCS files
# Convert the list of FCS files into a list of data frames
df = lapply(list, exprs)
df = lapply(df, as.data.frame)
我可以通过list
轻松获得文件名:
list[[1]]@description[['$FIL']]
此外,我可以手动创建列,但是我知道必须有更好/更快的方法!
df[[1]]$sample = list[[1]]@description[['$FIL']]
如果需要获取所有描述,元素将list
循环到lapply/sapply/Map
并使用匿名函数调用
dfNew <- Map(function(x, y) transform(y,
sample = x@description[["$FIL"]]), list, df)