Could you tell me how to use R to calculate the total value of the column and extract only columns with a total value of 100 or more into a data frame?
df<-data.frame(id=1:3, score1=c(200,30,100), score2=c(0,30,10), score3=c(90,40,10), score4=c(200,220,300))
The data frame looks like the one above.Thank you for your cooperation
r tidyverse
tidyverse
.
suppressMessages (library(tidyverse))
df<-data.frame (id=1:3, score1=c(200,30,100), score2=c(0,30,10), score3=c(90,40,10), score4=c(200,220,300))
df2<-df%>%select(id, where (~sum(.[.!="id"], na.rm=T)>=100))
df2
# id score1 score3 score4
# 1 1 200 90 200
# 2 2 30 40 220
# 3 3 100 10 300
© 2024 OneMinuteCode. All rights reserved.