Hey everyone !
So I'm working on an assignment for an R class and somehow, I got an error on a plot I don't really understand. For a bit of context, I'm trying to analyze the opinion of people about abortion according to their school degree, their religion and the year the data was collected.
Here's the code to first see the general trend on the opinion based on their religion :
religion <- project_data %>%
select(-year, -degree) %>%
na.omit
summary(religion)
plot(abany~religion, data=religion, main="Visualisation of the ratio Pro/Again Abortion based on religion")
abline(h=0.5, col="red")
and the error I get : Error in (function (formula, data = NULL, subset = NULL, na.action = na.fail, :
type (list) incorrect pour la variable 'religion'
My problem is... there isn't any list in my data !
str(religion)
'data.frame': 28533 obs. of 9 variables:
$ sex : Factor w/ 2 levels "Male","Female": 2 2 1 2 1 2 2 2 2 1 ...
$ relig : Factor w/ 13 levels "Protestant","Catholic",..: 2 2 4 2 1 2 2 2 1 2 ...
$ abany : Factor w/ 2 levels "Yes","No": 1 1 1 2 1 1 2 2 1 2 ...
$ abdefect: Factor w/ 2 levels "Yes","No": 1 1 1 1 1 1 1 2 1 1 ...
$ abnomore: Factor w/ 2 levels "Yes","No": 1 1 1 2 1 1 2 2 1 2 ...
$ abhlth : Factor w/ 2 levels "Yes","No": 1 1 1 1 1 1 1 2 1 1 ...
$ abpoor : Factor w/ 2 levels "Yes","No": 1 1 2 2 1 1 2 2 1 2 ...
$ abrape : Factor w/ 2 levels "Yes","No": 1 1 1 1 1 1 1 2 1 2 ...
$ absingle: Factor w/ 2 levels "Yes","No": 1 1 1 1 1 1 2 2 1 2 ...
- attr(*, "na.action")= 'omit' Named int [1:28528] 1 2 3 4 5 6 7 8 9 10 ...
..- attr(*, "names")= chr [1:28528] "1" "2" "3" "4" ...
I used the exact same code to create a plot based on the degree, which has the exact same type of data, and another one with the year of collection and everything worked fine, but for some reason I can't get my plot with the "religion" set.
degree<- project_data %>%
select(-year, -relig) %>%
na.omit
summary(degree)
plot(abany~degree, data=degree, main="Visualisation of the ratio Pro/Again Abortion based on the highest degree")
abline(h=0.5, col="red")
> str(degree)
'data.frame': 28185 obs. of 9 variables:
$ sex : Factor w/ 2 levels "Male","Female": 2 2 1 1 2 2 2 2 1 1 ...
$ degree : Factor w/ 5 levels "Lt High School",..: 1 1 4 4 2 2 1 2 1 2 ...
$ abany : Factor w/ 2 levels "Yes","No": 1 1 1 1 1 2 2 1 2 1 ...
$ abdefect: Factor w/ 2 levels "Yes","No": 1 1 1 1 1 1 2 1 1 1 ...
$ abnomore: Factor w/ 2 levels "Yes","No": 1 1 1 1 1 2 2 1 2 1 ...
$ abhlth : Factor w/ 2 levels "Yes","No": 1 1 1 1 1 1 2 1 1 1 ...
$ abpoor : Factor w/ 2 levels "Yes","No": 1 1 2 1 1 2 2 1 2 2 ...
$ abrape : Factor w/ 2 levels "Yes","No": 1 1 1 1 1 1 2 1 2 1 ...
$ absingle: Factor w/ 2 levels "Yes","No": 1 1 1 1 1 2 2 1 2 1 ...
- attr(*, "na.action")= 'omit' Named int [1:28876] 1 2 3 4 5 6 7 8 9 10 ...
..- attr(*, "names")= chr [1:28876] "1" "2" "3" "4" ...
Do you guys have any idea what can be wrong ?
Thanks in advance 1