Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to keep those strings that are repeated more than once

I have a data like this

mydf<- structure(list(rn = c("AAAA", "CDSD", "HUMN", "AAAA", "CRAT", 
"CAMSAP3", "RRR", "RRR", "AAAA", "AAAA", "NPRL2", "CDSD", "RAD18", 
"THAL", "BRO"), values = c(0.744760161, 0.741827081, 0.737886634, 
0.72658262, 0.71792587, 0.71787455, 0.674992626, 0.674716174, 
0.670139778, 0.668368874, 0.668332846, 0.663282622, 0.659781148, 
0.656606592, 0.656403592)), class = "data.frame", row.names = c(NA, 
-15L))

I am trying to remove those that are repeated 1 time and keep those that are more than once based on r column

I was trying something like this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

mydf$value_count <- rowSums(!is.na(mydf[-1])) 
mydf2 <- df[df$value_count > 1,]

I cannot figure it out

>Solution :

We may use subset from base R

subset(mydf, rn %in% names(which(table(rn) > 1)))

Or filter from dplyr

library(dplyr)
mydf %>%
    filter(rn %in% names(which(table(rn) > 1)))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading