Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Print r vector to copy paste into other code. [duplicate]

Tags:

r

I have a vector I'd like to copy paste into code to be able to produce a minimal working example.

Problem is, when I try to print the vector it produces output like

> head(residuals_list)
            1         2         3         4         5         6
    0.1833777 7.1833777 1.1833777 4.1833777 5.1833777 0.1833777

How do I get r to print c(0.1833777, 7.1833777, ...)?

like image 894
The Unfun Cat Avatar asked Feb 19 '14 13:02

The Unfun Cat


People also ask

How do you copy a line of code in R?

In RStudio, click File -> New File -> R Script (or Ctrl+Shift+N) to create a script, which you can save like a text file. Copy-paste all your code into that and click Ctrl+A (to select all lines) and Ctrl+R to run all at once.


1 Answers

With dput :

x =runif(5)
dput(x)

c(0.634340619435534, 0.833359521813691, 0.4804580679629, 0.119585362030193, 
0.379494784167036)
like image 163
Victorp Avatar answered Oct 04 '22 21:10

Victorp