NeatNerd
NeatNerd

Reputation: 2373

Get list of values for factor in R

I would like to convert values of factor into a list, how can i do it? P.S.: Sry, Im new to R

Example: i have the following factor:

> table(v)
v
       (0,80]      (80,500]    (500,1000]  (1000,10000] (10000,90000] 
         8259          2167           112            62             1 

how can i get:

 c(8259,2167,112,62,1) 

Upvotes: 3

Views: 1470

Answers (3)

Jonas Tundo
Jonas Tundo

Reputation: 6197

Or:

test <- as.vector(table(v)[])
test

Upvotes: 3

Andrie
Andrie

Reputation: 179428

use unname():

x <- table(cut(runif(100), 5))
x


(0.00448,0.202]   (0.202,0.399]   (0.399,0.596]   (0.596,0.794] 
             24              23              16              19 
  (0.794,0.991] 
             18 


unname(x)
[1] 24 23 16 19 18

Upvotes: 4

agstudy
agstudy

Reputation: 121568

You can transform the result of table to a data.frame and:

as.data.frame(x)$Freq
[1] 28 13 20 20 19

Upvotes: 3

Related Questions