Description Usage Arguments Details Value Note Author(s) References See Also Examples
This function subsets data frames into smaller dataframes including only participants who meet the critereon in the metadata.
1 | crop_counts(df, meta, variables, values)
|
df |
data frame with column names of the study_id's |
meta |
metadata dataframe |
variables |
The names of the columns in metadata that the dataframe is being subset based on. These variables should be listed together in one vector. |
values |
The desired values of the columns above. Listed together in one vector in the order that "variables" is listed. |
It is important that "variables" and "values" are the same length and cooresponding entries are in the same order.
The output is a subsetted version of the original data frame containing only the participants that contain the specified values for the specified variables.
no further notes
atomczik
no references
no additional functions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 | ##---- Should be DIRECTLY executable !! ----
##-- ==> Define data, use random,
##-- or do help(data=index) for the standard data sets.
## The function is currently defined as
function (df, meta, variables, values)
{
df.t = setNames(data.frame(t(df[, ])), row.names(df))
df.t$study_id <- row.names(df.t)
merged.data <- merge(meta, df.t, by = "study_id")
row.names(merged.data) <- merged.data$study_id
merged.data <- merged.data[, -1]
for (i in 1:length(variables)) {
variable.column <- which(names(merged.data) == variables[i])
merged.data = subset(merged.data, (merged.data[, variable.column] ==
values[i]))
}
cropped.counts <- merged.data
m <- length(meta)
n <- length(merged.data)
p <- m + 1
cropped.counts = cropped.counts[, m:n]
cropped.counts = setNames(data.frame(t(cropped.counts[, ])),
row.names(cropped.counts))
return(cropped.counts)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.