Re: [R] Recoding variables based on reference values in data frame

2013-07-03 Thread arun
Hi, May be this helps: Kgeno<- read.table(text=" SNP_ID SNP1 SNP2 SNP3 SNP4 Maj_Allele C G  C  A Min_Allele T A T G  ID1 CC    GG    CT    AA ID2 CC    GG    CC AA ID3 CC    GG nc  AA ID4  _  _  _  _ ID5 CC    GG    CC    AA ID6 CC    GG    CC  AA ID7 CC    GG    CT    AA ID8 _ _ _ _  ID9 CT   

Re: [R] Recoding variables based on reference values in data frame

2013-07-02 Thread Rui Barradas
Hello, If you have read in the data as factors (stringsAsFactors = TRUE, the default), change the function to the following. fun <- function(x){ x[x %in% c("nc", "_")] <- NA MM <- paste0(as.character(x[1]), as.character(x[1])) # Major Major Mm <- paste0(as.character(x

Re: [R] Recoding variables based on reference values in data frame

2013-07-02 Thread Rui Barradas
Hello, I'm not sure I understood, but try the following. Kgeno <- read.table(text = " SNP_ID SNP1 SNP2 SNP3 SNP4 Maj_Allele C G C A Min_Allele T A T G ID1 CC GG CT AA ID2 CC GG CC AA ID3 CC GGncAA ID4 _ _ _ _ ID5 CC GG CC AA ID6 CC GG CC