Thank you for your prompt response.
So having this:
URN QF0 Var1 Var2 Var3 Var4 Var5 Var6 Var7
1 21GB0421520600348376 2 0 2 0 0 0 0 0
2 21GB0418447730308396 6 0 2 4 0 0 0 0
3 21GB0424598350378907 33 1 0 0 0 0 32 0
4 21GB0418447730308382 35 1 2 0 0 0 32 0
5 21GB0420497680334731 32 0 0 0 0 0 32 0
6 21GB0416416410294317 4 0 0 4 0 0 0 0
7 21GB0424598350378906 33 1 0 0 0 0 32 0
8 21GB0412336390238885 1 1 0 0 0 0 0 0
9 21GB0424594550377080 32 0 0 0 0 0 32 0
10 21GB0418447730308379 64 0 0 0 0 0 0 64
11 21GB0414375210263918 2 0 2 0 0 0 0 0
12 21GB0424594550377079 64 0 0 0 0 0 0 64
13 21GB0414375210263920 2 0 2 0 0 0 0 0
14 21GB0418452110311403 8 0 0 0 8 0 0 0
15 21GB0423572270366131 33 1 0 0 0 0 32 0
Can I recode all values >=0 in variables starting with "Var" into 1s?
I believe, I should use somehow
mutate if
My second question is about R capabilities. I cannot find anywhere in R documentation using multi-response variables. Is my code of summary statistics the only way of displaying results of this one question? For other, typical tabulations we can use just a name of a variable and cross it with anything else, check frequencies, proportions, etc. Can we do it with one multiple-response-variable (let's call it "MultiVar") or the only way of checking valies of all Vars (Var1, Var2, Var3) is summary statistics?
I have added gender:
source <- data.frame(
stringsAsFactors = FALSE,
URN = c("21GB0421520600348376",
"21GB0418447730308396","21GB0424598350378907","21GB0418447730308382","21GB0420497680334731",
"21GB0416416410294317","21GB0424598350378906",
"21GB0412336390238885","21GB0424594550377080",
"21GB0418447730308379","21GB0414375210263918","21GB0424594550377079",
"21GB0414375210263920","21GB0418452110311403",
"21GB0423572270366131"),
QF0 = c(2, 6, 33, 35, 32, 4, 33, 1, 32, 64, 2, 64, 2, 8, 33),
Gender = c(2, 1, 2, 2, 2, 1, 2, 1, 2, 1, 2, 1, 2, 2, 1)
)
source
Once I recode all Var into 0/1 I would like to see results for each gender.
Is this the only way:
idea2 <- recoding %>%
select(Gender, starts_with("Var")) %>%
group_by(Gender) %>%
summarise_all(list(Count = sum, Proportion = mean)) %>%
pivot_longer(-Gender, names_to = c("Category", "summary"), names_sep = "_", "value") %>%
pivot_wider(names_from = summary, values_from = value)
idea2