Wednesday 15 August 2012

r - dplyr: count of a count -



r - dplyr: count of a count -

let's have info frame

df <- data.frame(x = c("a", "a", "b", "a", "c"))

using dplyr count, get

df %>% count(x) x n 1 3 2 b 1 3 c 1

i want count on resulting n column. if n column named m, result i'm looking is

m n 1 1 2 2 3 1

how can done dplyr?

thank much!

dplyr seems have problem count(n).

for instance:

d <- data.frame(n = sample(1:2, 10, true), x = 1:10) d %>% count(n)

a workaround rename n:

df %>% # using info defined in question count(x) %>% rename(m = n) %>% count(m)

r count dplyr

No comments:

Post a Comment