0

I can't figure out a way to get rid of this error in my R script.

I prepared Data in R and then wanted to use the prepareMplusData function, which works well until I standardize a variable.

setwd (...)
install.packages("merTools")
library(merTools)
data(hsb)

install.packges("MplusAutomation")
library(MplusAutomation)

prepareMplusData(hsb, "Mydata.dat") #it works now!
hsb$mathach <- scale(hsb$mathach) 
prepareMplusData(hsb, "Mydata_scales.dat") #now I get the error term

As soon as I scale my Data and try to use the prepareMplusData function, I get the following error:

Error in vapply(df, class, FUN.VALUE = NA_character_) : 
  values must be length 1,
 but FUN(X[[110]]) result is length 2

What can I do now? I never explicitly wrote the vapply code, so I assume, this is part of another function. How do I standardize my Data in a way, that I can export my Data to an Mplus format?

I found out how to fix it. just needed to specify the standardized variable to a numeric

rnewby
  • 1
  • 1
  • `*` and `**` are for emphasizing *text*, not for code. `\`` (inline) and `\`\`\`` (block) is used for *code*, and while it seems mostly stylistic and/or aeshetic, it can change the readability of the question significantly. Please see https://stackoverflow.com/editing-help. – r2evans Jul 02 '21 at 13:22
  • `scale` calls `apply` which calls `vapply`, that's a possible chain of function calls that leads to your error. Please consider making this question reproducible, there's very little we can do without sample data. – r2evans Jul 02 '21 at 13:25
  • sorry, Im pretty new here. How do I make this reproducible? Thank you for that information! Is there a different way to scale data without calling vapply? – rnewby Jul 02 '21 at 13:35
  • 1
    See https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info for some good discussions on making good reproducible questions. Thanks! – r2evans Jul 02 '21 at 13:37
  • Please can you heed my advice? If we naively try this code as-is, we'll first get `object 'a' not found`, then the same with `'b'`, and then I don't know what we'll get from `c(a,b,c)`, since we don't know what the first two are, and the third *might* be a `function` or it might be something else.. So *please* pay attention to [my previous comment](https://stackoverflow.com/questions/68225905/how-can-i-get-rid-of-this-error-warning-when-using-the-preparemplusdata-function?noredirect=1#comment120580494_68225905), read the links, then improve your question to make it reproducible. – r2evans Jul 04 '21 at 16:40
  • I hope it works now! Sorry! I used the hsb Data, which I think is available for everyone, right? – rnewby Jul 05 '21 at 06:31

0 Answers0