merging values from columns

image
i have created this table and now i want to merge 3 columns to "NoAd"

I use the record EEG from the "HRM" package

what is the best way to combine the 3 columns except "AD" to one column called "NoAd" including the values of course?

would be great if someone could help me, I've been sitting at it for days and I can't make it - I'm a real beginner\noob.

thanks

image
should be like that at the end.. after i use prop.table.

image
my code so far

Hi @SimonAustria, welcome to RStudio Community.

Please do not post screenshots of code as it just creates more work for the people trying to replicate it. Code pre-formatted as text is preferable.

As for your question, it's just a matter of combining the unwanted factor levels into the new level "No AD" before creating the contingency table.

library(HRM)
#> Loading required package: MASS
#> Loading required package: matrixcalc
#> Loading required package: plyr
#> Loading required package: ggplot2

EEG$group <- factor(EEG$group, 
                    levels = c("SCC+", "SCC-", "MCI", "AD"), 
                    labels = c("No AD", "No AD", "No AD", "AD"))

Kontingenz1 <- prop.table(table(EEG$sex, EEG$group), margin = 1)

addmargins(Kontingenz1, margin = 2)
#>    
#>         No AD        AD       Sum
#>   M 0.7966102 0.2033898 1.0000000
#>   W 0.7623762 0.2376238 1.0000000

Created on 2020-04-19 by the reprex package (v0.3.0)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.