如何在 tibbles 上取消 which.min
How to un-break which.min on tibbles
/R-新人。
我的 which.min 调用在我的数据框的一列上工作正常,但在加载 dplyr which.min 时不再工作。是因为 df 现在是 tibble 了吗?任何解决方法?
> which.min(Analytic_traces_raw[,1]) #********************WORKS FINE HERE**
[1] 1
> library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
> which.min(Analytic_traces_raw[,1]) #*********************NOW IT'S BROKEN**
Error in which.min(Analytic_traces_raw[, 1]) :
(list) object cannot be coerced to type 'double'
> head(Analytic_traces_raw[,1]) #**TYPE IS DBL, BUT TIBBLE TROUBLE**?
# A tibble: 6 x 1
`t_Pur23Mar18_TP7-24`
<dbl>
1 0.000417
2 0.00375
3 0.00708
4 0.0104
5 0.0138
6 0.0171
类似这样的问题可以通过在命令前指定包名来解决,例如
raster::which.min(Analytic_traces_raw[,1])
(或者如果您实际使用的 which.min
与 dplyr
或 raster
中的不同,请替换包名称)。这是一个示例(尽管不是给出不同结果的示例):
> data(iris)
> apply(iris, 2, raster::which.max)
$Sepal.Length
[1] 132
$Sepal.Width
[1] 16
$Petal.Length
[1] 119
$Petal.Width
[1] 101
$Species
integer(0)
> apply(iris, 2, base::which.max)
$Sepal.Length
[1] 132
$Sepal.Width
[1] 16
$Petal.Length
[1] 119
$Petal.Width
[1] 101
$Species
integer(0)
不是 which.min
"broke" 而是 "broke" R 中的默认行为。通常,对于数据帧,Analytic_traces_raw[,1]
会降低维度并成为向量. tibbles 改变了这种行为,因此期望 "normal" 行为的 R 函数将会中断。尝试 Analytic_traces_raw[[1]]
:
library(dplyr)
which.min(mtcars[,1])
[1] 15
> mtcars_tbl <- as_tibble(mtcars)
> which.min(mtcars_tbl[,1])
Error in which.min(mtcars_tbl[, 1]) :
(list) object cannot be coerced to type 'double'
> which.min(mtcars_tbl[[1]])
[1] 15
/R-新人。 我的 which.min 调用在我的数据框的一列上工作正常,但在加载 dplyr which.min 时不再工作。是因为 df 现在是 tibble 了吗?任何解决方法?
> which.min(Analytic_traces_raw[,1]) #********************WORKS FINE HERE**
[1] 1
> library(dplyr)
Attaching package: ‘dplyr’
The following objects are masked from ‘package:stats’:
filter, lag
The following objects are masked from ‘package:base’:
intersect, setdiff, setequal, union
> which.min(Analytic_traces_raw[,1]) #*********************NOW IT'S BROKEN**
Error in which.min(Analytic_traces_raw[, 1]) :
(list) object cannot be coerced to type 'double'
> head(Analytic_traces_raw[,1]) #**TYPE IS DBL, BUT TIBBLE TROUBLE**?
# A tibble: 6 x 1
`t_Pur23Mar18_TP7-24`
<dbl>
1 0.000417
2 0.00375
3 0.00708
4 0.0104
5 0.0138
6 0.0171
类似这样的问题可以通过在命令前指定包名来解决,例如
raster::which.min(Analytic_traces_raw[,1])
(或者如果您实际使用的 which.min
与 dplyr
或 raster
中的不同,请替换包名称)。这是一个示例(尽管不是给出不同结果的示例):
> data(iris)
> apply(iris, 2, raster::which.max)
$Sepal.Length
[1] 132
$Sepal.Width
[1] 16
$Petal.Length
[1] 119
$Petal.Width
[1] 101
$Species
integer(0)
> apply(iris, 2, base::which.max)
$Sepal.Length
[1] 132
$Sepal.Width
[1] 16
$Petal.Length
[1] 119
$Petal.Width
[1] 101
$Species
integer(0)
不是 which.min
"broke" 而是 "broke" R 中的默认行为。通常,对于数据帧,Analytic_traces_raw[,1]
会降低维度并成为向量. tibbles 改变了这种行为,因此期望 "normal" 行为的 R 函数将会中断。尝试 Analytic_traces_raw[[1]]
:
library(dplyr)
which.min(mtcars[,1])
[1] 15
> mtcars_tbl <- as_tibble(mtcars)
> which.min(mtcars_tbl[,1])
Error in which.min(mtcars_tbl[, 1]) :
(list) object cannot be coerced to type 'double'
> which.min(mtcars_tbl[[1]])
[1] 15