ilhan
ilhan

Reputation: 8944

How to select second row in R?

I want to select a second row from a table (or array?) but it returns an error.

a <- readLines(stdin(), n=1)

I enter 5 4 3 2 1 4 5 6 7 6 5 4

data <- strsplit(a, " ")
leafplot <- table(data)
leafplot[,2]

Then it returns an error

Error in `[.default`(leafplot, , 2) : incorrect number of dimensions

Upvotes: 0

Views: 1258

Answers (1)

www
www

Reputation: 39154

as.data.frame(leafplot)$Freq
# [1] 1 1 1 3 3 2 1

Or

as.matrix(leafplot)[, 1]
# 1 2 3 4 5 6 7 
# 1 1 1 3 3 2 1 

Upvotes: 1

Related Questions