1

What is the difference between these two lines of codes?

varname1 <- cbind(df.name$var1, df.name$var2, df.name$var3)

varname2 <- cbind(df.name[1:3])

If I then try to use the next function I get an "invalid type (list) for variable "varname2".

This is the next function I try to use:

manova(varname ~ indepvar.snack+judge+rep,data = df.name)

So why does varname1 works and varname2 not?

Afke
  • 899
  • 2
  • 10
  • 21
  • 1
    Maybe it's because their classes are different? `varname1` is a matrix whereas `varname2` is a dataframe. – Ronak Shah Dec 11 '17 at 04:09

1 Answers1

1

Nulling my previous answer as I originaly thought you are column binding a series of columns in to a single columned dataframe.

check str(varname1) since it results in matrix while str(varname2) is dataframe.

manova is accepting matrix-type variable as argument. do:

varname2 <- as.matrix(varname2)
addicted
  • 2,901
  • 3
  • 28
  • 49
  • Doesn't work for me, does it for you? What is the difference between [1:3] and [,1:3]? Thank you! – Afke Dec 11 '17 at 04:07
  • based on what I tried, actually the first one (`cbind(df$var1, df$var2`) results in matrix and second one results in data.frame. have you do `str(varname1)` and `str(varname2)`? – addicted Dec 11 '17 at 04:08
  • str(varname1) is num for me and the other one is a dataframe.. How can I change the dataframe into a num? Then the next function probably works. – Afke Dec 11 '17 at 04:12
  • 1
    as per my understanding, manova is accepting matrix type of argument. Can you try `varname2 <- as.matrix(varname2)`? – addicted Dec 11 '17 at 04:14
  • can you accept my answer if it helps and works? Thanks. @Papie – addicted Dec 11 '17 at 05:34