I have created the following data frame
df<-data.frame("A"<-c(1:20), "B"<-c(21:40),"C"<-c(11:30))
names(df)<-c("A", "B", "C")
nameslist<-c("A", "B")
I am trying to obtain the mean and weighted means for both columns combined
I have tried this
mean(df[,names(df)[names(df)%in%nameslist]])
I get the following error.
Warning message:
In mean.default(df[, names(df)[names(df) %in% nameslist]]) :
argument is not numeric or logical: returning NA
I have also tried computing the weighted mean as follows
weighted.mean(df[,names(df)[names(df)%in%nameslist]])
410
I am getting an output of 410 in this case. I am unable to uncover where I am wrong. I request someone to guide me here