0

I'm drawing a MCA plot using FactoMine R. I have data tables that look like this:

Met  Aa     Fn      Pg      Pi      Tf      Smut    Ssob    An      Csput
C1  High    N.S.    N.S.    N.S.    High    N.S.    High    High    N.S.
C2  High    N.S.    Low     High    N.S.    N.S.    N.S.    N.S.    N.S.
C4  High    High    N.S.    High    N.S.    N.S.    High    N.S.    High
C6  N.S.    N.S.    High    N.S.    N.S.    N.S.    N.S.    N.S.    High
C9  Low     Low     Low     Low     Low     High    N.S.    Low     Low
C12 N.S.    N.S.    Low     N.S.    N.S.    N.S.    High    N.S.    High

###So I loaded my data
metabolites<-read.csv2('MCA24h_carbon.csv',dec='.')##all metabolites at 24h

###Named the column
metID<-metabolites$met

###Created a new matrix
newmet<-subset(metabolites,select=-c(Met))

### and the number of categories per variable
cats<- apply (newmet, 2, function(x) nlevels(as.factor(x)))


#and this is the output I get from the analysis:
structure(c(85L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 1L, 
3L, 3L, 3L, 3L), .Names = c("Var", "Aa", "Fn", "Pg", "Pi", "Tf", 
"Smut", "Ssob", "An", "Csput"))

This was my first red sign... Afterwards, I performed the MCA just to see what will I get and this was the code:

mca1=MCA(metabolites, graph=FALSE)
mca1$eig
mca1$var$coord
mca1$ind$coord
mca1_var_df=data.frame(mca1$var$coord, Variable=rep(names(cats), cats))
mca1_obs_df= data.frame(mca1$ind$coord)

Then I get the following in the console:

Error in data.frame(mca1$var$coord, Variable = rep(names(cats), cats)) : 
  arguments imply differing number of rows: 269, 254

I'm very new using R (as in 1 week) but I have experience using SAS... I have no idea what I am doing wrong and why R is fixing my data into the above structure (3L, 3L, 3L...) Does anyone have any idea on how to proceed?

Thomas
  • 43,637
  • 12
  • 109
  • 140

1 Answers1

0

I had the same issue and I fix it by removing NA`s and also check that you have the same number of factor levels than labels for that factor!