【发布时间】:2025-11-21 09:25:01
【问题描述】:
我的问题是我在标题中所说的,我发现 Duck 的问题和我的一样 (How to create in R new variable for each element in a list of data frames with the name of data frame and its value equal to position of the element)。
在我对 R 的了解不足的情况下,虽然它确实得到了我想要的,但我无法很好地理解代码。
我知道我的代码无法运行,但我认为代码应该是这样的:
# create a fake data
df1 <- split(mtcars,mtcars$cyl)
# add a new variable that indicate where the element from in the list with the element name
df2 <- map(df1, mutate(from = names(df1)))
任何帮助将不胜感激!
【问题讨论】: