Skip to content
Prev 293914 / 398503 Next

How to deal with a dataframe within a dataframe?

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
+     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"
df$value
1 1.800534, 1.628483
2 1.299652, 1.261302
3 1.699018, 1.381570
4 1.311681, 1.067232
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)))
        )
    }
}