I am stuck here with another R-problem. I have a data frame of the following layout with over 2000 observations and 50 columns:
group <- c("X","X","X","X","Y","Y","Y","Y","Z","Z","Z","Z")
subgroup <- c("A","B","A","B","A","B","A","B","A","B","A","B")
obs1 <- c(rnorm(12,mean=10))
obs2 <- c(rnorm(12,mean=20))
e <- data.frame(group,subgroup,obs1,obs2)
What I would like to have is a dataframe showing the sum of all observations for a specific group x subgroup interaction like this: column1=group column2=subgroup column2=sum of obs1, column4=sum obs2 ....
group,subgroup and column labels should be preserved. I tried:
for(i in levels(e$group)){test[i,]<-as.matrix(Matrix::colSums(e[,3:4]))}
but this leads to an error. Probably you notice that I am not advanced with R coding :)