r - Counting the number of entries as a means of filtering data -
sorry if description vague - i'm extremely new r , finding hard visualise want do. suppose have data:
dat <- read.table(text = ' b c "mike" 1 1 "mike" 1 17 "mike" 1 3 "mike" 2 4 "mike" 3 18 "simon" 1 2 "simon" 1 25 "simon" 2 12 "simon" 2 182 "simon" 2 6', header=true) ... etc.
suppose want know number of names (a column) have 3 entries b = 1, , number of names have 3 entries b = 2, , on?
in illustration above, "mike" has 3 entries b = 1, not b = 2 or b = 3. "simon" has 3 entries b = 2, , on. it's crossing entries in data, i've not done yet in r, , i'm not sure how best approach it.
i believe you're after (but realize code's terribly dense r newbie, , perchance not-so-newbies):
tab <- table(dat[1:2]) m <- max(tab) apply(rbind(tab, m), 2, tabulate) - c(rep(0, m-1), 1) # 1 2 3 # [1,] 0 1 1 # [2,] 1 0 0 # [3,] 1 1 0
values of b along top while frequencies (number of people having count of b=1
, b=2
, , b=3
) along side.
r
No comments:
Post a Comment