I do a calculation and visualize data in Excel with count_if function, but I don't find a way to do this in R.
I have a table 1 with the answers, I want to count the total answers and group by category of answer like a table 2, finally make data visualization. All the process like this photos.
Please help find a way to do this in R, thank you
To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:
Thank you for your help, I want to count all the answers of all the column and group to new table, like an example I do in Excel, it is not hard to do in Excel when I use count_if and select the ranges and criteria, but I don't know how to write a code in R.
df |>
tidyr::gather() |> # pool all columns into one
dplyr::count(value, name = "count") # count values in this one column, same as previous answer.
PS: there is no direct way to do this because the spreadsheet design is actually not perfect. You usually do not need to count cell over different columns, as different columns should indicate different kind of information. The function gather()indeed clean your data first (telling all columns are actually the same kind of data and should be merged) and then it is easy to count (or do other calculations).