[英]Loop through data frames to produce new column
I have 10 data frames (Shape1,Shape 2,Shape 3 etc.), each containing the same the column names.我有 10 个数据框(Shape1、Shape 2、Shape 3 等),每个数据框都包含相同的列名。 How do i for loop this command through the 10 data frames so each contains a new column called integration?
我如何在 10 个数据帧中循环此命令,以便每个数据帧都包含一个称为集成的新列?
Shape1$Integration<-cumtrapz(Shape1$Time, Shape1$CA)
many thanks非常感谢
In base R, you can create a list of dataframe using mget
, loop over each and create a new column with transform
.在基础 R 中,您可以使用
mget
创建 dataframe 列表,遍历每个列表并使用transform
创建一个新列。
lapply(mget(paste0("Shape", 1:10)), function(x)
transform(x, Integration = cumtrapz(Time, CA)))
In tidyverse
that can be done as在
tidyverse
中,可以这样做
library(tidyverse)
map(mget(paste0("Shape", 1:10)), ~.x %>% mutate(Integration = cumtrapz(Time, CA)))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.