Home > Enterprise >  Error: Data should be a matrix or data frame
Error: Data should be a matrix or data frame

Time:05-19

R gives me this absurd error message even if the data ARE in a data.frame format. Last time I used this script, everything worked fine.

> is.data.frame(Dataset)
[1] TRUE

I tried everything from restart R, restart my Pc, gc(), rm(list=ls()). I'm trying to do a for loop and this error stops it all. Every library useful for this is correctly installed and called in the R session. The [-1] in the loop refers to the ID column.

for(i in 2:length(Dataset[-1])) {
  Dataset[,i] <- impute(Dataset[,i], "random")

}

I can't give you the dataset because there are sensible data inside: is there a solution?

CodePudding user response:

one solution:

library(dplyr)
library(Hmisc)
 
Dataset %>%
  mutate(across(-1, ## skip first column
                function(column) Hmisc::impute(column, "random")
         )
         )

CodePudding user response:

There may be an answer to your mistake https://www.scribbr.com/statistics/type-i-and-type-ii-errors/

  • Related