How to subset when with two different variables (to make a barplot)

67 Views Asked by At

I am trying to make a subset with with two different variables, however when I run this code:

progressive.vote.demo <- subset(dbj, subset == progressive.vote & republican == 0)

it comes up with this error message:

Error in subset == progressive.vote : comparison (1) is possible only for atomic and list types

This is so I can make a table to run a barplot:

democrats.table <- table(democrats$judge.birthyear == "before 1935",
democrats$judge.birthyear == "from 1935", dbj$progressive.vote)

barplot(democrats.table)
1

There are 1 best solutions below

0
On

Could it be you are trying to pass a variable instead of a character string (say "progressive.vote")? More clarification would be welcomed.

dbj=as.data.frame(cbind(subset=c(rep("progressive.vote",2),rep("conservative.vote",2)),republican=c(0,1,0,1)))
dbj
     subset              republican
[1,] "progressive.vote"  "0"       
[2,] "progressive.vote"  "1"       
[3,] "conservative.vote" "0"       
[4,] "conservative.vote" "1"    

subset(dbj, subset == "progressive.vote" & republican == 0)
        subset republican
1 progressive.vote          0