:
dplyr,
library(dplyr)
integrates2 %>% group_by(name) %>% summarise(prg1 = program[1],
prg2 = program[2],
prg3 = program[3]) %>%
select(prg1, prg2, prg3) %>% group_by(prg1, prg2, prg3) %>% summarise(freq = n())
Source: local data frame [2 x 4]
Groups: prg1, prg2 [?]
prg1 prg2 prg3 freq
(fctr) (fctr) (fctr) (int)
1 ffp TP NA 2
2 TP ffp wfd 1
mydf2
Source: local data frame [3 x 4]
Groups: prg1, prg2 [?]
prg1 prg2 prg3 freq
(chr) (chr) (chr) (int)
1 ffp TP NA 1
2 TP ffp NA 1
3 wfd TP ffp 1
group_by on name ;summarise program ;select, ;group_by prg*,summarise freq .
R, , ( , ):
tab <- table(sapply(split(integrages2$program, integrates2$name),
function(x){paste(x, collapse = '-')}))
prgs <- strsplit(names(tab), '-')
programs <- do.call(rbind, lapply(prgs, function(x){
c(x, rep(NA, max(sapply(prgs, length)-length(x))))
}))
programs <- cbind(as.data.frame(programs), matrix(tab))
names(programs) <- c(paste0('prgm', seq(length(programs)-1)), 'freq')
, :
table(sapply(split(integrates2$program, integrates2$name),
function(x){paste(x, collapse = '-')}))
ffp-TP TP-ffp-wfd
2 1
as.matrix,
[,1]
ffp-TP 2
TP-ffp-wfd 1
:
reshape2, dcast, data.frame ( name s, , [,-1]):
library(reshape2)
programs <- dcast(integrates2, name ~ program, value.var = 'program')[,-1]
programs :
> programs
ffp TP wfd
1 ffp TP wfd
2 ffp TP <NA>
3 ffp TP <NA>
dplyr programs ( , group_by(ffp, TP, wfd), , ) summarise, n() :
library(dplyr)
programs %>% group_by_(.dots = names(programs)) %>% summarise(freq = n())
Source: local data frame [2 x 4]
Groups: ffp, TP [?]
ffp TP wfd freq
(chr) (chr) (chr) (int)
1 ffp TP wfd 1
2 ffp TP NA 2