I have a simple questioon I think. In my dataframe I would like to make subset where column Quality_score is equal to: Perfect, Perfect*, Perfect*, Good, Good** and Good***
This in my solution by now:
>Quality_scoreComplete <- subset(completefile,Quality_score == "Perfect" | Quality_score=="Perfect***" | Quality_score=="Perfect****" | Quality_score=="Good" | Quality_score=="Good***" | Quality_score=="Good****")
Is there a way to simplify this method? Like:
methods<-c('Perfect', 'Perfect***', 'Perfect****', 'Good', 'Good***','Good***')
Quality_scoreComplete <- subset(completefile,Quality_score==methods)
Thank you all,
Lisanne
You do not even need subset, check: ?"["
Quality_scoreComplete <- completefile[completefile$Quality_score %in% methods,]
EDITED: based on kind comment of @Sacha Epskamp: == in the expression gives wrong results, so corrected it above to %in%. Thanks!
Example of the problem:
> x <- c(17, 19)
> cars[cars$speed==x,]
speed dist
29 17 32
31 17 50
36 19 36
38 19 68
> cars[cars$speed %in% x,]
speed dist
29 17 32
30 17 40
31 17 50
36 19 36
37 19 46
38 19 68
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With