Assuming your data is a data.frame df
, for the mean
sapply(subset(df,select=-c(LK)),function(x){mean(x*df$LK)})
for the mean and median
sapply(subset(df,select=-c(LK)),function(x){c(mean(x*df$LK),median(x*df$LK))})
but perhaps you are searching for a weighted average of LK, each column containing the weights, in which case
sapply(subset(df,select=-c(LK)),function(x){weighted.mean(df$LK,x)})
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…