[R] dput(treat)

Rui Barradas ruipbarradas at sapo.pt
Wed Oct 11 13:27:47 CEST 2017


Hello,

The best way to post data is to use dput. The moderator/admin (?) did 
NOT say that you should "first get the structure, and then assign it 
back", they gave you an example of the use of dput and then what us, 
when reading your post would do with that output.

They wrote that "Then we can just do this".

We can simply assign that output to a variable and create an exact copy 
of what you have in your R session, that's why dput is so usefull.

When you post data, always post the output of dput. If it's a large 
dataset, such as a data.frame with many rows, you can post a small 
subset with

dput(head(df, 20))  # or 30 or 50

This will only give the structure of the first 20 (or 30 or 50) rows.


Hope this helps,

Rui Barradas

Em 11-10-2017 11:59, Ted Beginner (RStudio) via R-help escreveu:
>
> I got advice here that I didn't understand! Can I ask to explain me the meaning of this procedure: first get the structure, and then assign it back. For what? Thanks!  (Great thanks to Moderator/Admin!)
>
> You should learn to post in plain text and use dput to present your data structures. At your console do this
> dput(treat)
> # and this will appear. Copy it to your plain-text message:
> structure(list(ID = 1:5, start = c(0L, 0L, 0L, 0L, 0L), stop = c(66L,
> 18L, 43L, 47L, 26L), censor = c(0L, 0L, 1L, 1L, 0L), sex = c(2L,
> 1L, 2L, 2L, 1L), age = c(1L, 2L, 3L, 3L, 4L), stage = c(3L, 4L,
> 3L, NA, 3L), treatment = c(1L, 2L, 1L, 2L, NA)), .Names = c("ID",
> "start", "stop", "censor", "sex", "age", "stage", "treatment"
> ), class = "data.frame", row.names = c("1", "2", "3", "4", "5"
> )):
> Then we can just do this:
>   treat <- structure(list(ID = 1:5, start = c(0L, 0L, 0L, 0L, 0L), stop = c(66L,
> 18L, 43L, 47L, 26L), censor = c(0L, 0L, 1L, 1L, 0L), sex = c(2L,
> 1L, 2L, 2L, 1L), age = c(1L, 2L, 3L, 3L, 4L), stage = c(3L, 4L,
> 3L, NA, 3L), treatment = c(1L, 2L, 1L, 2L, NA)), .Names = c("ID",
> "start", "stop", "censor", "sex", "age", "stage", "treatment"
> ), class = "data.frame", row.names = c("1", "2", "3", "4", "5"
> ))
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list