I am new to R, please help me out with this embarrassing question.
How do I get the %, ratio of the data in the graph shown in a summary/table ? I need the marital status and the weight in % for each category. I tried a code but failed miserably, please advice.
Thanks in advance
Christine
I am looking for a table something similar to this.
Marital Excellent Very good
Married % %
Divorced % %
Widowed
Hello Martin,
Thank you very much! It does not seem to partition over the right data as it does not add to 100%.
I am looking for nbr of married in excellent genhlth/ total married.
Also, It does not make the data very easy to read. Is there not a way to not repeat the variables?
Something like this?
Marital Excellent Very good
Married % %
Divorced % %
Widowed
Hello,
Thank you but now I ran your first code
sleep_cleaned <- tibble(
marital = sample(c("Married", "Divorced", "Widowed"), 50, T),
genhlth = sample(c("Excelent", "Very Good", "Fair"), 50, T),
id = sample(1:1000, 50, T))
and I want to return my dataset to what it was, how do I do that?
Oh I am sorry. I used this first portion only to build sample data for the example. You can completely ignore it as you already have the real data. Cheers.
I am encountering some difficulties with rendex so I can't produce an example.
Error: Install these packages in order to use the reprex addin:
shinyjs
In addition: Warning message:
In flat_str(content, breaks) : Coercing content to character
I was merely asking for a reproducible example because I didn't understand what you wanted, but LVG77 did and provided the example data to produce the solution.
aahh perfect!!! That was exactly what I needed. Was not as easy as I thought. So it was not possible without downloading extra packages?
Thank you so much.
The tidyverse is a convenient package of packages.
You were already using dplyr and ggplot2. tidyr was required for the spread function, so you could either load the packages individually or just tidyverse on its own in which case you don't need to load dplyr or ggplot2 separately.