- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个看起来像这样的示例数据框(我的完整数据框有“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"
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.`
最佳答案
可能是这样的:
library(tidyverse)
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
Example_Ratio <- example %>%
mutate_at(vars(-Zr), funs(. / Zr)) %>%
select(Ratio_Elements)
我知道你说你想看
mutate_all
解决方案,但我猜你不想分割
Zr
通过它自己?
mutate_at
更有帮助,否则你可以做
mutate_all(funs(. / Zr))
.
Detrital_Divisor <- as.symbol("Zr")
Example_Ratio <- example %>%
mutate_at(vars(- !! Detrital_Divisor), funs(. / !! Detrital_Divisor)) %>%
select(Ratio_Elements)
funs
自
dplyr 0.8.0
起弃用,您可以使用
~
,例如:
Detrital_Divisor <- as.symbol("Zr")
Example_Ratio <- example %>%
mutate_at(vars(- !! Detrital_Divisor), ~ . / !! Detrital_Divisor) %>%
select(Ratio_Elements)
另一方面,还有
list
- 用于以多种方式变异或命名输出,例如:
Example_Ratio <- example %>%
mutate_at(vars(- !! Detrital_Divisor), list(appended_name = ~ . / !! Detrital_Divisor))
dplyr 1.0.0
,你可能想使用
across
:
Example_Ratio <- example %>%
mutate(across(-Detrital_Divisor, ~ . / !! Detrital_Divisor)) %>%
select(all_of(Ratio_Elements))
关于r - 使用 mutate_all 将所有列除以选定的列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54030049/
你有没有注意到 Excel Vba 代码中除法 2/60 的问题?我正在使用 Excel 2013。请测试以下代码: Sub test1() Dim A As Integer Dim B As Int
我正在运行长时间的模拟。我将结果记录到 vector 中以计算有关数据的统计信息。我意识到,理论上,这些样本可能是除以零的结果。这只是理论上的,我很确定事实并非如此。为了避免修改代码后重新运行模拟,我
我有一些可以包含字母、数字和“#”符号的字符串。 我想删除除以“#”开头的单词以外的数字 下面是一个例子: "table9 dolv5e #10n #dec10 #nov8e 23 hello" 预期
我有以下代码,问题是我尝试将 Double 除以 Int factorial :: Int -> Int factorial 0 = 1 factorial e = e * (factorial e-
我有以下查询,它试图计算出某种产品占产品总数的百分比。 IE:[产品数量]/[产品总数] = 百分比 ;WITH totalCount AS( SELECT CAST(COUN
我正在解析字符串,然后需要将其转换为数字。但如果它包含除以 0 的例子 String str1 = "1+2+3-5/0+4+6" String str2 = "1+2+3-4/0.000 +4+6"
这个问题已经有答案了: Right Shift to Perform Divide by 2 On -1 (6 个回答) 已关闭 9 年前。 在阅读 Collections.reverse 的 Jav
我是 C++ 新手。我听说除以0会导致运行时错误,但是当我尝试时,它抛给我一个编译器错误C2124并且没有创建目标文件,所以编译器会自动运行代码以查看它是否可以在创建之前执行目标文件? (顺便说一句,
我试图在 codefights.com 上解决这个问题,方法是找出最大的质因数并将该数字除以质因数的幂。 int highestPower(int N, int A) { int B =A, j=0,
我对在不同计算机上运行程序有疑问。 我用 C++\windows 7 64 位\Visual Studio 编写了一个程序,该程序在我的计算机上完美运行。 当我尝试在另一台计算机(Windows 7
这个问题已经有答案了: Division in C++ not working as expected (6 个回答) 已关闭 9 年前。 Helo,我是编程新手,遇到了一个问题,我有一个整数,例如
我正在做某事,但遇到了一个我不明白的问题。 double d = 95.24 / (double)100; Console.Write(d); //Break point here 控制台输出是 0.
我需要仅使用按位运算符(例如 ! & ^ ~ 和移位)来计算数字 (a/(2**b)。我得到了以下提示,但我是 C 新手,我不知道什么是代码含义: int bias = x>0 ? 0 : ((1>b
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Java Integer division: How do you produce a double? 当我
嗨,我正在尝试将 numpy 数组分成两部分,并在一个循环中进行此操作,例如: main_array.shape = (50, 400, 400, 3) for i = 0: sub_array_1
这是片段: String myTime = someTime / 1e9d + ","; someTime 是使用 System.nanoTime() 派生的。 1e9d 在这里做什么? 最佳答案 1
Random random = new Random(); int randomx = random.Next(0, 240); 这是我获取随机数的方式,从 0 到 240,如何才能只获取除以 5 的
我一直在处理一个应用程序,因为图像表现得很奇怪,所以我决定打开 Wall 标志,看看是否有任何奇怪的事情发生。它揭示了一个新的警告: character.cpp(364): warning C4723
我是 Android Studio 的新手,我正在开发一个计算器应用程序。现在,当我除以零时,自然会收到错误消息“Infinity”,但如果我想将其更改为“不能除以零”,我该怎么做呢? impor
如何显示每 5 日创建一个新行的表中的数据 ? 例子 data: [1,2,3,4,5,6]; 成分: {{item}} 预期的: | 1 | 2 | 3 | 4 | 5 | | 6 |
我是一名优秀的程序员,十分优秀!