Using R, I'm trying to find a more efficient way to calculate the differences between the largest value in a column and each value in that same column. I was able to do this, but the code looks bulky (I created a vector where each value is the max value of the column), I'm hoping someone can demonstrate a more efficient method, perhaps using the apply command?
a<-data.frame("Group Name"=c('Group 1','Group 2', 'Group 3', 'Group 4','Group 5', 'Group 6'),
"app 1"=c(28,28,27,28,29,28),
"app 2"=c(32,31,29,33,35,32),
"app 3"=c(44,43,42,45,46,44),
"app 4"=c(48,48,47,48,49,48),
"app 5"=c(38,36,35,39,41,38),
"app 6"=c(26,26,25,26,27,26))
a$Avg_score=apply(a[,-1],1,mean)
a$max_mean_diff<-c(max(a$Avg_score),max(a$Avg_score),max(a$Avg_score),
max(a$Avg_score),max(a$Avg_score),max(a$Avg_score))-a$Avg_score
View(a)