[R] Help with code
William Dunlap
wdunlap at tibco.com
Wed Dec 21 20:05:18 CET 2011
To make it so others can produce
your dataset on their own computers (so
they can easily reproduce the problem you are
having) do, in R,
dump("c1", file=stdout())
and copy the text output by that that into your message.
E.g., suppose I made a data.frame with
junk <- data.frame(x=runif(4),y=runif(4))
and forgot to save the random seed before making it.
Instead of sending the calls to runif I could use dump():
> dump("junk", file=stdout())
junk <-
structure(list(x = c(0.415693838847801, 0.399903971236199, 0.999439711682498,
0.331607921980321), y = c(0.827737988438457, 0.193867813330144,
0.0372913987375796, 0.62276106630452)), .Names = c("x", "y"), row.names = c(NA,
-4L), class = "data.frame")
and would copy all of its output into the mail message
(there is no need to copy the dump() command itself).
It isn't pretty but it gets the job done without any fuss.
Some mailers like to break lines that they consider
too long and that can change the meaning of the code
produced by dump(). If your mailer does that, use
dump("c1", file="c1.txt") # or "c:/temp/c1.txt", etc.
and attach the file c1.txt to your mail message.
We will see if my mailer breaks up the lines in my
example.
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of 1Rnwb
> Sent: Wednesday, December 21, 2011 10:07 AM
> To: r-help at r-project.org
> Subject: Re: [R] Help with code
>
> I do not know how to use dput, i am attaching the txt file for the data
> http://r.789695.n4.nabble.com/file/n4222616/foo.txt foo.txt
>
> c1<-read.dlim('foo.txt')
> c2<-c1
>
> any_comp<-NULL
>
> for( i in 1:dim(c1)[1])
> {
> num_comp<-0
> for (j in 1:dim(c1)[2])
> if (c1[i,j]==2) num_comp=num_comp+1 #"Y"=2
> for (j in 1:dim(c1)[2])
> if(num_comp>0)
> {
> if (data$t1d_ptype[i] == "T1D" && c1[i ,j] == 2) c2[i,j]<-"T1D_w"
> if (data$t1d_ptype[i] == "T1D" && c1[i, j] == 1) c2[i,j]<-"T1D_oc"
> if(substr(data$t1d_ptype[i],1,4) == "Ctrl" && c1[i,j] == 2)
> c2[i,j]<-"Ctrl_w"
> if (substr(data$t1d_ptype[i],1,4) == "Ctrl" && c1[i,j] == 1)
> c2[i,j]<-"Ctrl_oc"
> }
> else
> {
> if(data$t1d_ptype[i] == "T1D") c2[i,j]<-"T1D_noc"
> if(substr(data$t1d_ptype[i],1,4) == "Ctrl") c2[i,j]<-"Ctrl_noc"
> }
> }
>
> this gives me whether the particular t1d_ptype has a specific complication
> as well as there is another complication as well.
>
> I will appreciate help very much.
> thanks
> sharad
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Help-with-code-tp4218989p4222616.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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