Subset problem in R

2

I'm having problems using subset in R . I believe it's an easy question, but I'm not getting it right.

I want to make a% d of data that I can keep, only observations that do not have the value of the variable subset is not equal to X.trimws.relcoop.SITUAÇÃO ... b ... and the value of the variable Cancelada not equal to risco .

So that's what I came for:

dados<-data.frame(subset(dados,(X.trimws.relcoop.SITUAÇÃO...b...!="Cancelada"&risco!="Não classificada")))

I've also tried this:

dados<-dados[dados$X.trimws.relcoop.SITUAÇÃO...b... != "Cancelada" & dados$risco!= "Não classificada", ]

But in both Não classificada of my data is being done by subset instead of or .

I am sorry to ask such an easy question, but I believe this answer will help me on the logic of and and maybe it can help others.

    
asked by anonymous 24.11.2016 / 13:42

1 answer

2

To remove only those lines that are "Unclassified" and "Canceled", the easiest way is as follows:

Consider this data.frame :

df <- data.frame(
  x = c("Cancelada", "Outro", "Outro", "Cancelada"),
  y = c("Não classificada", "Não classificada", "Outro", "Outro")
)

subset(df, !(x == "Cancelada" & y == "Não classificada"))
          x                y
2     Outro Não classificada
3     Outro            Outro
4 Cancelada            Outro

You could also change the & (e) to | (or):

subset(df, x != "Cancelada" | y != "Não classificada")
    
24.11.2016 / 14:08