Message-ID: <OFCB30D1F8.4EEEB979-ONC125796E.0027BE75-C125796E.00289FDF@precheza.cz>
Date: 2011-12-22T07:23:32Z
From: PIKAL Petr
Subject: Help with code
In-Reply-To: <1324490847580-4222616.post@n4.nabble.com>
Hi
>
> I do not know how to use dput, i am attaching the txt file for the data
dput(any.object)
puts a structure of this object to console. You can copy it to your email
and anybody can copy it back to R.
Or you can transfer the structure to file see
?dput, ?dget
> 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
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
this line is never true. There is no 2 in a c1.
Maybe you shall really tell us what is your intention with some simple
example.
Here is a subset of your file c1
my.c1 <- structure(list(HTN = structure(c(2L, 1L, 1L), .Label = c("",
"Y"), class = "factor"), HTN_FDR = structure(c(2L, 2L, 2L), .Label = c("",
"Y"), class = "factor"), Dyslipidemia = structure(c(2L, 1L, 2L
), .Label = c("", "Y"), class = "factor"), CAD = c(NA, NA, NA
), CAD_FDR = structure(c(2L, 2L, 1L), .Label = c("", "Y"), class =
"factor"),
Prior_MI = c(NA, NA, NA)), .Names = c("HTN", "HTN_FDR",
"Dyslipidemia",
"CAD", "CAD_FDR", "Prior_MI"), row.names = c("1", "5", "9"), class =
"data.frame")
Forget your complicated code and tell us what is you desired output?
Regards
Petr
> 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.