Open willpearse opened 7 years ago
Thanks again for helping me with this. I haven't played with the code above yet, but had a question on the second DNA question. See below for my error with the provided code:
sequence <- 'ACTATGAGTA' translate <- function(sequence){ a <- sapply(seq(from=1, to=nchar(sequence), by=3), function(cnt) substr(sequence, cnt,cnt+2)) b <- table$amino[c(match(a, table$codon))] return(cat(b,sep='')) } protein = translate(sequence)
*_Error in output[i, 1] <- translate(multiseq[i, 1]) : number of items to replace is not a multiple of replacement length_**
multiseq <- matrix(data = c('ACTATGAGTA', 'ACTAGTATAGA'))
multitrans <- function(multiseq){ output <- matrix(nrow=(nrow(multiseq)), ncol=1) for(i in 1:(nrow(multiseq))){ output[i,1] <- translate(multiseq[i,1]) return(output) } }
multitrans(multiseq)
Check the length of both of the things in the error. Take a break - you'll see it when you're fresh.
Office hours are over! 8pm here! On Fri, 4 Nov 2016 at 19:32, Spencer Hudson notifications@github.com wrote:
Thanks again for helping me with this. I haven't played with the code above yet, but had a question on the second DNA question. See below for my error with the provided code: This works fine
sequence <- 'ACTATGAGTA' translate <- function(sequence){ a <- sapply(seq(from=1, to=nchar(sequence), by=3), function(cnt) substr(sequence, cnt,cnt+2)) b <- table$amino[c(match(a, table$codon))] return(cat(b,sep='')) } protein = translate(sequence) But I get this error when I run the code below it
* Error in output[i, 1] <- translate(multiseq[i, 1]) : number of items to replace is not a multiple of replacement length**
multiseq <- matrix(data = c('ACTATGAGTA', 'ACTAGTATAGA'))
multitrans <- function(multiseq){ output <- matrix(nrow=(nrow(multiseq)), ncol=1) for(i in 1:(nrow(multiseq))){ output[i,1] <- translate(multiseq[i,1]) return(output) } }
multitrans(multiseq)
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/pearselab/r-intro-Spencerbrucehudson/issues/7#issuecomment-258526911, or mute the thread https://github.com/notifications/unsubscribe-auth/ABLcUmRlZaRtE-JERmtCU2-OoZ4UbF88ks5q64g-gaJpZM4Kp2Yy .
All good. Figured it out. Breaks are truly something aren't they.
Something along these lines will give you what you want...
Note that
some.sort.of.plot.code
probably wants to be the same across the two lines