any suggestions on the following gratefully welcome,
I have a dataframe, which I am subsetting via labels
atpi[, creativity]
where (for example)
atpi = as.data.frame(matrix(1:50, ncol = 5, nrow = 10))
names(atpi) = c("Q1", "Q2", "Q3", "Q4", "Q5")
and
creativity = c("Q1", "Q3", "Q4")
I want to add an extra column to the dataframe atpi labelled "creativity",
which is the rowsum of these 3 columns. My problem is not the rowsum but
but the passing of an argument to a function, which is being used for subsetting
but also for labelling the rowsum column. I can do a one-off hack for
creativity,
but I want to generalise this, as I have numerous subsets
like creativity) to calculate and some pre-processiing (imputing
missing data etc)...
so I'm looking for something simple along the lines of
scoring = function(x, A){
x[, A] = rowSums(x[, A])
x
}
where a call such as
scoring(atpi, creativity)
would produce something along the lines of