我想从表(或数组?)中选择第二行,但返回错误。
a <- readLines(stdin(), n=1)
我输入5 4 3 2 1 4 5 6 7 6 5 4
data <- strsplit(a, " ")
leafplot <- table(data)
leafplot[,2]
然后返回错误
Error in `[.default`(leafplot, , 2) : incorrect number of dimensions
答案 0 :(得分:1)
as.data.frame(leafplot)$Freq
# [1] 1 1 1 3 3 2 1
或
as.matrix(leafplot)[, 1]
# 1 2 3 4 5 6 7
# 1 1 1 3 3 2 1