Extract data out of R

I am using a package that returns data in this format(list)

What are the proven ways of extracting them into excel

I have tried a couple of things that did not work, unlist, write.table, converting to dataframe. all failed.

Any other ways

It is really almost impossible to see what is happening in a screenshot . Can you give us the data in a dput format?

A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need. Just do dput(mydata) where mydata is your data. Copy the output and paste it here.

For general information see FAQ Asking Questions

At a guess you need to store that output in a variable and then export to .csv or xlsx format. Just exporting to .csv and reading that file into Excel is probably the easiest method.

## Generate some data
xx  <- rnorm(100)

## write xx to disc, 
 write.csv(xx, "xx.csv", row.names = FALSE)

One way would be to convert it to a data frame and then use the writexl package. The example below assumes your data is assigned to x.

mydata = data.frame(col1 = x)

writexl::write_xlsx(mydata, path = “your_file_path_name/mydata.xlsx”)

Those response gives me Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) :
cannot coerce class ‘"spei"’ to a data.frame! And I have tried those options.

What package are you using to generate the data? Can you provide some sample code to assist in troubleshooting?

xlsx_xlsx is in the {xlsx} package which, IIRC, is a brute for a beginner to install.
You code is throwing an error. It looks like

write_xlsx(mydata, path = “your_file_path_name/mydata.xlsx”)

has some kind of invisible character in it.

I rewrote it as

 xx  <- rnorm(100)
mydata = data.frame(xx)
write.xlsx(mydata, "mydata.xlsx")

and it seems fine.

A handy package for importing and export a wide variety of file formats is {rio}

export(mydata, "rio.xlsx")
export(xx, "rioxx.xlsx")

Good catch! I meant to list the writexl package (corrected above).

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.