我正在读取一系列以数据框列表形式结束的文件。在这样做之后,我有兴趣添加与每个数据框相关的额外信息。因此,我想向数据框列表中的每个元素添加一些额外元素。
我的尝试是实际上构建“额外内容”列表,然后尝试将其与数据框列表合并。
示例代码:
我的尝试是实际上构建“额外内容”列表,然后尝试将其与数据框列表合并。
示例代码:
set.seed(42)
#Building my list of data.frames. In my specific case this is coming from files
A <- data.frame(x=rnorm(10), y=rnorm(10))
B <- data.frame(x=rnorm(10), y=rnorm(10))
ListD <- list(A, B)
names(ListD)<- c("A", "B") #some names to know what is what
#now my attributes. Each data.frame as some properties that i want to keep track of.
newList <- list(A=c("Color"=123, "Date"=321), B=c("Color"=111, "Date"=111))
#My wished output is a list were each element of the list has
#"Color", "Date" and a dataframe
#I tried something like:
lapply(ListD, append, values=newList)