Hello all,
I am doing an aggregation where the aggregating function returns not a
single numeric value but a vector of two elements using return(c(val1,
val2)). I don't know how to access the individual columns of that
vector in the resulting dataframe though. How is this done correctly?
Thanks, robert
▾ Quoted text (1 line)
agg <- aggregate(formula=df$value ~ df$quarter + df$tool,
+ FUN=cp.cpk, lsl=1300, usl=1500)
df$quarter df$tool df$value
1 09Q3 VS1A 1.800534, 1.628483
2 10Q1 VS1A 1.299652, 1.261302
3 10Q2 VS1A 1.699018, 1.381570
4 10Q3 VS1A 1.311681, 1.067232
df$value
1 1.800534, 1.628483
2 1.299652, 1.261302
3 1.699018, 1.381570
4 1.311681, 1.067232
[1] "data.frame"
▾ Quoted text (1 line)
head(agg["df$value"][1]) # trying to select 1st column
df$value
1 1.800534, 1.628483
2 1.299652, 1.261302
3 1.699018, 1.381570
4 1.311681, 1.067232
▾ Quoted text (1 line)
head(agg["df$value"][2]) # trying to select 2nd column
Error in `[.data.frame`(agg["df$value"], 2) : undefined columns selected
# FWIW, here's the aggregating function
function(data, lsl, usl) {
if (length(data) < 15) {
return(NA)
} else {
return (c(
(usl-lsl)/(6*sd(data)),
min(mean(data)-lsl, usl-mean(data))/(3*sd(data)))
)
}
}
Message-ID:
<CAMXbmUTQAuT_1JNtVw_MWoaaDFeg+krj2ytTfBz1-ffabt68Hw@mail.gmail.com>