I am trying to generate a data frame based on a user-defined function. My problem is that in the output only the first row is being filled. Here is an example of the functi
There are two problems with the function:
Col_T
with all NA
s as the first statement inside the for loop.Rewrite it as follows:
myfunc <- function(X, system, Title ) {
Col_T <- data.frame(matrix(NA, ncol=length(X), nrow=4 ));
for (i in 1:4)
Col_T[i,] <- colSums(X[which(df$yr==i & df$cs==system),]);
return(Col_T);
};