Resa
April 14, 2021, 10:52am
1
Hello,
How can i create with the Variable, Catholic, from the Data "swiss" in R logical variables like the following?
Evangelical: if the proportion of Catholics is below 25 percent.
Catholic: if the proportion of Catholics is over 75 percent.
Mixed: if the proportion of Catholics is between 25 and 75 percent.
and how can I get the frequencies from the variables listed above?
many thanks
FJCC
April 14, 2021, 12:34pm
2
Do you mean something like this? Calculating the mean of a Logical vector gives you the fraction of elements that are TRUE because TRUE is equal to 1 and False is equal to 0.
data("swiss")
swiss$Evg_region <- swiss$Catholic < 25.0
head(swiss)
Fertility Agriculture Examination Education Catholic Infant.Mortality Evg_region
Courtelary 80.2 17.0 15 12 9.96 22.2 TRUE
Delemont 83.1 45.1 6 9 84.84 22.2 FALSE
Franches-Mnt 92.5 39.7 5 5 93.40 20.2 FALSE
Moutier 85.8 36.5 12 7 33.77 20.3 FALSE
Neuveville 76.9 43.5 17 15 5.16 20.6 TRUE
Porrentruy 76.1 35.3 9 7 90.57 26.6 FALSE
mean(swiss$Evg_region)
[1] 0.5744681
Resa
April 14, 2021, 1:31pm
3
hi,
thank you for the fast reply. Yes that should be it.
system
Closed
May 5, 2021, 1:31pm
4
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.