简体   繁体   中英

R - How can I filter data column to show specific values

I have a dataframe with this structure : dataframe I have tried to only show the data where ukb_AD has value using this

ukb <- read.csv("mydata.csv", header=TRUE, sep="," )
ukb_EID <- ukb$ï..EID
Ukb_AD  <- ukb$Date.of.alzheimer.s.disease.report.0.0
df <- data.frame(ukb_EID,Ukb_AD)
df
mydf1 <- df %>% filter(!is.na(Ukb_AD) | Ukb_AD  != "{}"  | Ukb_AD  != "")
mydf1

but I'm still getting the same values.. filter is not working !!

You want & not | .

This is the difference between logical and colloquial use of "or". If I ask you for a candy that is "not a red candy OR not a green candy", you can give me literally any candy. Even a green candy meets the "not a red" candy criterion, and the "OR" means you only have to meet one criterion.

But if I ask for a candy that is "not a red candy AND not a green candy", the "AND" means you have to meet both criteria, so you can't give me red or green candies ;)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM