sorting based on all columns element and select with a threshold

前端 未结 2 1683
别那么骄傲
别那么骄傲 2021-01-25 06:39

I have a data looks like this

df<- structure(list(V1 = structure(c(6L, 2L, 3L, 7L, 5L, 4L, 8L, 1L
), .Label = c(\"A0A0G2JDV6\", \"P01901\", \"P13745\", \"Q03         


        
2条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-25 07:26

    Edit : The sorting is done wrong in this answer. Please refer to Procrastinatus Maximus's answer where it is correct. Thanks for pointing it out Procrastinatus Maximus :)

    Sort by all the five columns in descending order

    df2 <- df[order(df$V2, df$V3, df$V4, df$V5, df$V6, decreasing = TRUE), ]
    

    Keep only the rows where all values are greater than 1.1

    df3 <- df2[apply(X = df2[paste0("V", 2:6)], MARGIN = 1, FUN = function(x) all(x > 1.1)), ]
    

    Let me know if it helps

提交回复
热议问题