![](/img/trans.png)
[英]How to loop through a list of data frames and assign the numeric portion of the name as a new column value for the data frame?
[英]Loop through data frames to produce new column
我有 10 个数据框(Shape1、Shape 2、Shape 3 等),每个数据框都包含相同的列名。 我如何在 10 个数据帧中循环此命令,以便每个数据帧都包含一个称为集成的新列?
Shape1$Integration<-cumtrapz(Shape1$Time, Shape1$CA)
非常感谢
在基础 R 中,您可以使用mget
创建 dataframe 列表,遍历每个列表并使用transform
创建一个新列。
lapply(mget(paste0("Shape", 1:10)), function(x)
transform(x, Integration = cumtrapz(Time, CA)))
在tidyverse
中,可以这样做
library(tidyverse)
map(mget(paste0("Shape", 1:10)), ~.x %>% mutate(Integration = cumtrapz(Time, CA)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.