如何在R中选择第二行?

时间:2018-10-28 15:12:19

标签: r

我想从表(或数组?)中选择第二行,但返回错误。

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

1 个答案:

答案 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