Search code examples
rcsvsample

How do take a vector and copy paste it in to my R code as if I typed it out manually?


for example

sample.int(100,6) might create a vector 7,43,42,97,1,23

I want to take whatever vector it creates and put it in my R script so it never changes.

how do I take this vector and paste it in to an R script so it looks like c(7,43,42,97,1,23)?

What I'm doing now is writing the sample.int vector to a csv, opening the csv in notepad which shows all the numbers neatly separated by a comma and then copy/pasting it back in to my R script.


Solution

  • You can use the same function that is recommended when you need to provide data for an SO reprex:

    dput(sample.int(100,6))
    #> c(1L, 66L, 45L, 22L, 33L, 61L)