I have this data frame
df <- data.frame(subjects = 12:23,
Why_are_you_not_happy =
c(1,2,"1,2,5",5,1,2,"3,4",3,2,"1,5",3,4),
why_are_you_sad =
c("1,2,3",1,2,3,"4,5,3",2,1,4,3,1,1,1))
df
that is coverted into this format
df1 <- df %>%
separate(Why_are_you_not_happy,
sep = ",", into = c("Why_are_you_not_happy_1",
"Why_are_you_not_happy_2",
"Why_are_you_not_happy_3")) %>%
separate(why_are_you_sad,
sep = ",", into = c("why_are_you_sad_1",
"why_are_you_sad_2",
"why_are_you_sad_3"))
when applying the MCA function we take all the columns except the first one
library(FactoMineR)
library(factoextra)
#> Loading required package: ggplot2
results <- MCA(df1[,2:7])
However when looking at the graph of the individuals, they are labeled from 1 to 12, and what I wish is that the labels come from the subjects column. How can I make that ? Thanks.
CodePudding user response:
We could set the row names to subjects column
library(FactoMiner)
MCA(`row.names<-`(df1[-1], df1$subjects))