0
votes

I have created a new dataset in R and want to export it to excel to error check it. I am trying to use the xlsx package and when I run my export code I get this error: Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class ‘structure("crPar", package = "randomizeR")’ to a data.frame. I tried google searching this error code and nothing came up. Does anyone know what this error menas and how I can solve it? Below is my code. It's the last line that throws the error message.

K<- 2
GTP4<- randomizeR::crPar(581, K = 2, ratio = rep(1, K), groups = 
LETTERS[1:K])

library(xlsx)
xlsx::write.xlsx(GTP4, "D:/T Drive/GTP Factor analysis/GTP4.xlsx")
1
The object returned by crPar isn't a data frame, or even a data set, really, that I can tell. It's a special S4 object. If you want to save that object to a file, you'd have to use something like saveRDS. - joran

1 Answers

0
votes
K<- 2
GTP4<- randomizeR::crPar(581, K = 2, ratio = rep(1, K), groups = 
LETTERS[1:K])

GTP4 
## Object of class "crPar"

## design = CR 
## N = 581 
## groups = A B 


GTP4 is not a data.frame and cannot be converted to a dataframe for output by write.xlxs hence the error.

I suggest you read the randomizeR package documentation. the crPar class is used by the genSeq function to generate random sequences based on the model. Other functions are used to analyze the generated sequences. Nothing I can see that you can export to a spreadsheet.