KostraApply | R Documentation |
Apply a function with data frame output over data subsets
KostraApply(data, by, Fun, ...)
data |
Data frame |
by |
Vector of variable names (or variable numbers) defining the subsets or alternatively a named list or data frame (see examples). |
Fun |
Function to be applied on data subsets |
... |
Arguments passed to Fun |
A data.frame
The output ordering of the example depends on getOption("stringsAsFactors")
z1w <- KostraData("z1w")
zz <- rbind(cbind(aar=2014,z1w),cbind(aar=2015,z1w))
zzz <- rbind(cbind(ab="b",zz),cbind(ab="a",zz))
zzz$annet[c(1,9,17,25)] =10*(1:4)
# All subset in data by vector input
KostraApply(zzz, by = c("aar", "ab"), Fun = ProtectKostra, idVar = "region", freqVar = 4:7)
# Selected subsets by using list input to specify each variable
KostraApply(zzz, by = list(aar = c(2014, 2015), ab = "a"), Fun = ProtectKostra, idVar = "region", freqVar = 4:7)
# Or use NULL when all values in data
KostraApply(zzz, by = list(aar = NULL, ab = "a"), Fun = ProtectKostra, idVar = "region", freqVar = 4:7)
# Selected subsets by using data frame input to specify variable combinations
KostraApply(zzz, by = data.frame(aar = c(2014, 2015), ab = c("b", "a")), Fun = ProtectKostra, idVar = "region", freqVar = 4:7)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.