I have a dataset that look something like this:
groupA <- rbinom(n=50,size=1,prob=0.5)
groupB <- rbinom(n=50,size=1,prob=0.5)
groupC <- rbinom(n=50,size=1,prob=0.5)
groupD <- rbinom(n=50,size=1,prob=0.5)
dtTest <- cbind(groupA, groupB, groupC, groupD)
where 0 means "no" and 1 means "yes".
Now, i want to create a table with a column Group and another column answer, stating yes or no.
How can this be done ?
I tried the melt function and data.table group by, but keep getting error.
We may use
stackon the data.frame converted -cbindby default returns a matrix and not a data.frame. Instead, we may directly usedata.frame(groupA, groupB, ...)-output
For
data.table::melt, we may specify themeasureas the column names, (after converting to data.table -as.data.table)-output