The function enrollment. other does the following: (1) Takes in a data frame of 26 columns (2) Changes class of columns 1-2 to factor (3) Changes class of columns 3-26 to numeric (4) Creates column 27 as sum of columns 3-26 (5) Deletes all columns except 1 and 27 (6) Changes column name of 2nd column
- If the data frame i am reading in is x, I want the second column name to be xENRL.
But when I call the function the following error appears:
z <- enrollment.other(OBC) Warning message: In colnames(x)[2] <- sprintf("%sENRL", name) : number of items to replace is not a multiple of replacement length
enrollment.other <- function(x){
x[, 1:2] <- as.data.frame(sapply(x[, 1:2], as.factor))
x[, 3:26]<- as.data.frame(sapply(x[, 3:26], as.numeric))
x[, 27] <- rowSums(x[, c(3:26)])
x <- as.data.frame(x[, c(1, 27)])
name <- deparse(substitute(x))
colnames(x)[2] <- sprintf("%sENRL", name)
as.data.frame(x)
}