2

I have a simple problem. I have two variables and want to apply count(), plyr package, so as to find out how many 1s and 2s "a" scores, how many 1s and 2s "b" scores etc. Trying to do so, I just get error messages.

x=c(rep(1,5), rep(2,5))
y=c("a", "a", "b", "c", "d", "b", "a", "c", "c" ,"c")
df=data.frame(x,y) 
df2=count(df$x, df$y)

Thanks!

Spaniel
  • 329
  • 3
  • 15

1 Answers1

0

Won't table(df) suffice?

   y
x   a b c d
  1 2 1 1 1
  2 1 1 3 0

or t(table(df)):

   x
y   1 2
  a 2 1
  b 1 1
  c 1 3
  d 1 0

or data.frame(table(df)) %>% arrange(x):

  x y Freq
1 1 a    2
2 1 b    1
3 1 c    1
4 1 d    1
5 2 a    1
6 2 b    1
7 2 c    3
8 2 d    0
Deepak Rajendran
  • 358
  • 1
  • 11