Try this:

xNew <- as.data.frame(mapply(paste, x, x, sep = "/"))
xNew[is.na(x)] <- NA
xNew

On Thu, Feb 17, 2011 at 2:54 PM, Josh B <joshb41@yahoo.com> wrote:

> Hi all,
>
> I'm having a problem once again, trying to do something very simple.
> Consider
> the following data frame:
>
> x <- read.table(textConnection("locus1 locus2 locus3
> A T C
> A T NA
> T C C
> A T G"), header = TRUE)
> closeAllConnections()
>
> I am trying to make a new data frame, replacing "A" with "A/A", "T" with
> "T/T",
> "G" with "G/G", and "C" with "C/C." Note also the presence of an "NA"
> (missing
> data) in the data frame, which should be carried over to the new data
> frame.
>
> Here is what I am trying, which fails miserably:
>
> x2 <- data.frame(matrix(nrow = nrow(x), ncol = ncol(x)))
>
> for (i in 1:nrow(x)){
>    for (j in 1:ncol(x)){
>        if(x[i, j] == 'A') {x2[i, j] <- 'A/A'} else{
>            if(x[i, j] == 'T') {x2[i, j] <- 'T/T'} else{
>                 if(x[i, j] == 'G') {x2[i, j] <- 'G/G'} else{
>                    if(x[i, j] == 'G') {x2[i, j] <- 'G/G'} else{x2[i, j] <-
> NA}
>                }
>           }
>       }
>    }
> }
>
> I get the following error message:
> Error in if (x[i, j] == "A") { : missing value where TRUE/FALSE needed
>
> So what am I doing wrong? If you can provide me with specific code that
> fixes
> the problem and gets the job done, that would be the most useful.
>
>
> Thanks very much in advance for your help!
>
> Sincerely,
> -----------------------------------
> Josh Banta, Ph.D
> Center for Genomics and Systems Biology
> New York University
> 100 Washington Square East
> New York, NY 10003
> Tel: (212) 998-8465
> http://plantevolutionaryecology.org
>
>
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

	[[alternative HTML version deleted]]

