Pivot like number manipulation in R -
i trying nest 2 subset data inside aggregate. returns different length of data , hence unable compute. options have?
newfile<- aggregate(cbind(subset(iva,iva$ivr.agent =="agent"),subset(iva,iva$ivr.agent=="ivr")) ~ iva$orderno, fun = length, rm.action = true)
below error got
error in data.frame(..., check.names = false) : arguments imply differing number of rows: 25039, 4585
i trying make pivot table show agent count , ivr count in separate columns in excel, if specific order there no ivr shows null otherwise count.
dataset looks this
orderno ivr/agent a1 ivr b1 agent a2 agent b2 ivr a3 agent b3 agent a4 agent b4 agent a5 ivr b5 agent
so, wanna check out reshape2
package , cast
function. check out code below:
# install.packages('reshape2') # run if haven't downloaded before library(reshape2) datcast <- dcast(dat, orderno ~ ivr.agent, fun.aggregate = length, margins = t) datcast orderno agent ivr (all) 1 a1 0 1 1 2 a2 1 0 1 3 a3 1 0 1 4 a4 1 0 1 5 a5 0 1 1 6 b1 1 0 1 7 b2 0 1 1 8 b3 1 0 1 9 b4 1 0 1 10 b5 1 0 1 11 (all) 7 3 10
Comments
Post a Comment