How to create a label variable from a binary matrix with multiple columns

How to create a label variable from a binary matrix with multiple columns

0

Hello! I am trying to get a label variable from a binary matrix (df). The df matrix has multiple columns (n=981), and I want to get a categorical variable with 3 especific labels based on all the df columns.

First, I created a small matrix and tried with the next code:

Example:

my_sample_col <- data.frame(sample = rep(c("A", "B", "C"), c(2,3,4)))
row.names(my_sample_col) <- colnames(df)
my_sample_col

Output:

However, these results are not the correct labels for each column of the df matrix.

Correct labels must be as below:

Output_true:

I was wondering if someone could help me to fix this error. Finally, I would like to get a categorical variable with 3 especific labels based on all the df columns (n=981)

Please, I would be very grateful by their awesome help.


dataframe


R

• 39 views

Read more here: Source link