中位数:需要数字数据(Median : need numeric data)
为什么常规子集化可能无效? 我想从data.table中计算中位数:
> median(DT.UsersA3[,1]) Error in median.default(DT.UsersA3[, 1]) : need numeric data它是数字,但:
> class(DT.UsersA3$Timedif) [1] "numeric"随着虹膜数据框架的运行:
> median(iris[,3]) [1] 4.35词汇子集也适用于...
> median(DT.UsersA3$Timedif) [1] 422.046Why regular subsetting might not work? I wanted to calculate median from a data.table:
> median(DT.UsersA3[,1]) Error in median.default(DT.UsersA3[, 1]) : need numeric datait is numeric though:
> class(DT.UsersA3$Timedif) [1] "numeric"With iris data frame it works:
> median(iris[,3]) [1] 4.35And lexical subsetting also works...
> median(DT.UsersA3$Timedif) [1] 422.046最满意答案
这是iris的例子:
library(data.table) Iris <- data.table(iris) median(Iris[,1]) # Error in median.default(Iris[, 1]) : need numeric data Iris[,1] # is a data.table Iris[,Sepal.Length] # is a vector要使用列的编号,您可以按照Dason的评论:
Iris[[1]] # would return a vector median(Iris[[1]]) # worksHere is the example with iris:
library(data.table) Iris <- data.table(iris) median(Iris[,1]) # Error in median.default(Iris[, 1]) : need numeric data Iris[,1] # is a data.table Iris[,Sepal.Length] # is a vectorTo use the number of the column you can follow the comment from Dason:
Iris[[1]] # would return a vector median(Iris[[1]]) # works更多推荐
发布评论