r - conditional query with few vectors -



r - conditional query with few vectors -

this question has reply here:

checking equality 1 reply

short question.. next illustration data:

equips <- c(1000829,1000829,1000829,1000829,10002244,10002244, 10002244,10002244,10002244,10002244) notifs <- c(306989814,306991263,306991263,306991263,306749278,306749278, 306749278,306749278,306854440,306868916) comps <- c("ignition , flame detection","ignition , flame detection","control box", "ignition , flame detection","service boiler!!!","ch components passive", "ignition , flame detection","not grouped in wcc", "electrical components","flue duct") rank <- c(1,2,2,2,1,1,1,1,2,3) df <- data.frame(equips,notifs,comps,rank)

equip number machine, there 2 machines, notifs number visits => rank show number of visit machine. comps components repaired. want take if there components, repaired in every visit of machine.

for illustration machine 1, ignition , flame detection in rank 1 , rank 2 repaired, want have output true, machine 2 visited 3 times, there no component repaired in rank1,2 , 3 output should false. ( original dataset, has equips visited 10 times!!)

i had similar question , had code.

but not working. maybe can hind it:

result <- by(df, df$equips, function(d) { nb.comps <- length(unique(df$comps)) tab <- table(df$rank, df$comps) > 0 tab <- margin.table(tab, 2) return(sum(tab>=nb.comps)>0) }) data.frame(nb.equips=dim(result), nb.matched=sum(result))

i want this, because have no chance install packages, , because of size of info set, need overall view lastly code. if have questions please ask.

maybe ? problem in code replaced d df within function. seems me reply right in your original question...

result <- by(df, df$equips, function(d) { nb.comps <- length(unique(d$comps)) tab <- table(d$rank, d$comps) > 0 tab <- margin.table(tab, 2) return(sum(tab>=nb.comps)>0) })

which gives :

r> result df$equips: 1000829 [1] true -------------------------------------------------------- df$equips: 10002244 [1] false r> data.frame(nb.equips=dim(result), nb.matched=sum(result)) nb.equips nb.matched 1 2 1

r compare

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -