繁体   English   中英

RStudio hist() 错误:x 必须是数字,当所有列都是数字时

[英]RStudio hist () error: x must be numeric, when all of columns are numeric

我有一个 Excel 文件,其中包含数据(22 列,63 行(带标题)),例如:

Number  Indicator     R1     R2    R3     R4     R5     R6 ... R20
     1          1   0.05   0.11   0.1   0.78   2.28   0.43     0.02
     2          1  -0.07   0.15  0.04   0.77   1.14   0.18    -0.07

我的代码是:

data <- read_excel("C:/Users/.../name.xlsx")

par(mfrow=c(10,2))

i <- 3

for (i in 3:22)
{
hist((data[,i]), main = paste ("Distribution of ", colnames(data[i])),xlab = colnames(data[i]))
}

但是我得到一个错误“x 必须是数字”。

当我检查时:

sapply(data, is.numeric)

我的所有专栏都为 TRUE。

函数 dput(data) 给出:

data <- structure(list(Number = c(1, 2, 3, 4, 5, 6), Indicator= c(1, 
1, 1, 1, 1, 1), R1 = c(0.0468670885138916, -0.074745996240877, 
0.327157864485238, -0.0387491502379334, 0.0421560182280665, 0.168144355644356
), R2 = c(0.112696574983492, 0.15217635690426, 0.408386663040076, 
-0.362274813052345, 0.109485633993688, 0.0731946624803768), R3 = c(0.101172269417655, 
0.039415376952984, 0.225904124563141, -0.0760537049626105, 0.00572436316269123, 
0.0862887112887113), R4 = c(0.784787181194576, 0.768052257175519, 
2.51594161058083, 0.191575536654516, 0.723499020511543, 22.2366108439728
), R5 = c(2.27729101832578, 1.144481198922, 2.17308590402192, 
1.09326138681169, 0.646545133510631, 0.247754031682603), R6 = c(0.43267963792598, 
0.177028891725371, 1.01859825410429, 0.145989123045547, 0.184199187294186, 
0.102115741401456), R7 = c(0.276373048612796, 0.137142545743158, 
0.856234195681774, -0.162609011627907, 0.0143028375905503, 3.00490774678512
), R8 = c(0.737007324729683, 0.388610760253773, 2.07789466086862, 
0.511138112596193, 0.762444455169518, 4.57436577681976), R9 = c(0.366071402133714, 
0.287404442869258, 0.263834504277496, 0.467709041468389, 0.400225698323893, 
0.0287159269302126), R10 = c(-0.147145500013945, -0.543627851588112, 
-1.34733171298742, 0.190874843030557, -0.230556402706402, -8.73135710977304
), R11 = c(0.0716978139071031, 0.073683320767213, 0.177668199347725, 
0.217616882359799, 0.170491219963015, 0.0081652637869831), R12 = c(1.44695513401763, 
1.4259535502145, 0.141096873670778, 0.543977140816144, 2.98581972227625, 
15.6269841269841), R13 = c(0.0134075168556294, 0.00490014298911011, 
0.0451818513063426, 0.0196507477906186, 0.000117188847574234, 
0.129691736834594), R14 = c(0.0366254145433956, 0.0170496424487746, 
0.171250729430072, 0.042014898255814, 0.000292806903867018, 4.51636950984656
), R15 = c(1.57790823917327, 0.367304962433587, 0.500795219594211, 
0.045265780730897, 0.544757850800664, 0.0894705182582893), R16 = c(2.6375005026338, 
1.95510264690451, 0.0455660827482789, -1.21040974529347, 9.20224035944073, 
0.0154264815821993), R17 = c(169.851810954064, 233.560775974385, 
48.0964334393458, 55.6345945945946, 5517.12169625247, 1.91033012379642
), R18 = c(0.560290891001744, 0.547227376024043, 0.284418830219084, 
0.839225016995241, 0.580215009175459, 0.0430355358926788), R19 = c(1.33511336776679, 
1.87328815612566, 0.571574055480651, 3.55179704016913, 1.32834259355669, 
0.839257618802616), R20 = c(0.0205801929295569, -0.0653099380848556, 
0.150549899513746, -0.0354436283082663, 0.0652019728292849, 0.678674548714367
)), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame"
))

Function ncol(数据) 返回:

22

我能做到吗?

检查是否没有空单元格,并确保空单元格在 read_excel 中获得 NA。

查看 63 个值:

data[,3]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM