在 R 中使用除法运算符
Apply with division operator in R
如何在 R 中的应用调用中使用除法运算符?
我尝试在 R 中将 apply
与 n x 2 矩阵和除法运算符一起使用,语法如下:
apply(matrix,1,function)
我让 function
在这些可能性中变化:/
、"/"
、division
、divide
、rdivision
、rdivide
.
None 有效。
我最后得到了 A[,1]/A[,2]
。
你可以这样做
`/`
但是由于 R 被概念化为使用矢量化计算。
matrix / someVar
也许是更简单的方法。
正如@Georgery 所指出的,matrix / someVar
是最简单的方法。如果你还想使用apply,你可以使用下面的:
# choose the value with which every row value is divided
someVar = 2.5
# apply for each row, where row_val equals the values in your rows
apply(matrix, 1, function(row_val) row_val / someVar)
如何在 R 中的应用调用中使用除法运算符?
我尝试在 R 中将 apply
与 n x 2 矩阵和除法运算符一起使用,语法如下:
apply(matrix,1,function)
我让 function
在这些可能性中变化:/
、"/"
、division
、divide
、rdivision
、rdivide
.
None 有效。
我最后得到了 A[,1]/A[,2]
。
你可以这样做
`/`
但是由于 R 被概念化为使用矢量化计算。
matrix / someVar
也许是更简单的方法。
正如@Georgery 所指出的,matrix / someVar
是最简单的方法。如果你还想使用apply,你可以使用下面的:
# choose the value with which every row value is divided
someVar = 2.5
# apply for each row, where row_val equals the values in your rows
apply(matrix, 1, function(row_val) row_val / someVar)