我有一个示例数据框,它看起来像这样(我的完整数据框有"d"加上57个元素):
d <- seq(0, 100, 0.5)
Fe <- runif(201, min = 0, max = 1000)
Ca <- runif(201, min = 0, max = 1000)
Zr <- runif(201, min = 0, max = 1000)
Ti <- runif(201, min = 0, max = 1000)
Al <- runif(201, min = 0, max = 1000)
example <- data.frame(d, Fe, Ca, Zr, Ti, Al)
Ratio_Elements <- c("Fe", "Ti", "Zr", "d") #this subset of the
dataframe is user defined
Detrital_Divisor <- "Zr"
Detrital_Divisor可能会根据用户输入而更改,但它将始终是“example”数据帧中的一列。 我想使用管道将所有剩余列除以Detrital_Divisor列。 目前我有:
Example_Ratio <- example %>%
select (Ratio_Elements) #to subset to the user selected elements
mutate_all(./Detrital_Divisor)
但是我收到了错误:
Error in Ops.data.frame(., Detrital_Divisor) :
‘/’ only defined for equally-sized data frames.
我也尝试过:
Example_Ratio <- example %>%
select (Ratio_Elements)
sweep(., Detrital_Divisor, MARGIN = 1, '/')
基于在该论坛上类似的问题,但我就是无法让它工作。我收到了以下错误信息:
`Error in Ops.data.frame(x, aperm(array(STATS, dims[perm]), order(perm)), :
list of length 206340 not meaningful.`
我知道这个问题有点重复,但是其他我找到的答案在我的情况下都不起作用。我的整个数据框中有57个元素,因此编写将每列单独分开的代码会非常冗长。
提前感谢任何建议。