Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to export R data frame into code for sharing?

Tags:

dataframe

r

I'm trying to write a question for Stack Overflow, and I need to include a data frame so that my data can be replicated. I would like to take a data.frame object, and output code. I.e., I want to take this data.frame:

> dat
  a b
1 1 4
2 2 5
3 3 6

And turn it into this code without having to write it all out myself:

> dat <- data.frame(a=c(1,2,3),b=c(4,5,6))

My data.frame is very large, and I need to have a large number of observations for my question to make sense. Therefore it would be great if there is a package that will write that code out for me.

Thanks a lot for any and all advice.

like image 698
ejn Avatar asked Feb 22 '26 22:02

ejn


1 Answers

dput(dataframeName)

in your case: dput(dat)

like image 104
CuriousBeing Avatar answered Feb 24 '26 15:02

CuriousBeing



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!