[R] Help with code

Petr PIKAL petr.pikal at precheza.cz
Tue Dec 27 08:26:53 CET 2011


Hi

Can you explain rules for propagating values? I do not see any pattern. 
Only when there is no Y in a line you want to fill all columns with either 
T1D_noc or Ctrl_noc based on t1d_ptype.

I would start with narrowing the levels in last column as it seems to me 
there is no difference between Ctrl and Ctrl_FDR in desired result

levels(c1$t1d_ptype)[1:2] <- "Ctrl"
If you want to retain old values just make a new column with t1d_ptype and 
change levels only in this new column.

select all rows without Y
selection<-which(rowSums(c1[,1:6]=="")==6)

change columns 1:6 to character instead of factors
c1[,1:6]<-sapply(c2[,1:6], as.character)

put values from last column to other columns and add "noc"
c1[selection,1:6]<-paste(c1[selection,7], "noc", sep="_")

and after that I am lost.

Petr


> 
> structure(list(HTN = 1:10, HTN_FDR = structure(c(4L, 2L, 1L, 
> 2L, 3L, 1L, 1L, 2L, 3L, 2L), .Label = c("Ctrl_noc", "T1D_noc", 
> "T1D_oc", "T1d_w"), class = "factor"), Dyslipidemia = structure(c(3L, 
> 2L, 1L, 2L, 4L, 1L, 1L, 2L, 4L, 2L), .Label = c("Ctrl_noc", "T1D_noc", 
> "T1D_oc", "T1D_w"), class = "factor"), CAD = structure(c(3L, 
> 2L, 1L, 2L, 3L, 1L, 1L, 2L, 3L, 2L), .Label = c("Ctrl_noc", "T1D_noc", 
> "T1D_oc"), class = "factor"), CAD_FDR = structure(c(3L, 2L, 1L, 
> 2L, 3L, 1L, 1L, 2L, 3L, 2L), .Label = c("Ctrl_noc", "T1D_noc", 
> "T1D_oc"), class = "factor"), Prior_MI = structure(c(3L, 2L, 
> 1L, 2L, 3L, 1L, 1L, 2L, 3L, 2L), .Label = c("Ctrl_noc", "T1D_noc", 
> "T1D_oc"), class = "factor"), t1d_ptype = structure(c(3L, 3L, 
> 2L, 3L, 1L, 1L, 2L, 3L, 3L, 3L), .Label = c("Ctrl", "Ctrl_FDR", 
> "T1D"), class = "factor")), .Names = c("HTN", "HTN_FDR", "Dyslipidemia", 

> "CAD", "CAD_FDR", "Prior_MI", "t1d_ptype"), class = "data.frame", 
row.names
> = c(NA, 
> -10L))
> 
> 
> --
> View this message in context: http://r.789695.n4.nabble.com/Help-with-
> code-tp4218989p4228759.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