Hi I'm a biologist and new to coding in R. I'm trying to write a small program for designer primers; you input a string of characters ATGC for DNA, and it reverses the order and swaps the DNA bases over( A becomes T, T becomes A, G becomes C, C become G). I can get it to give me back the opposite DNA to the first character in the string, but it doesn't loop through the whole string. Any help much appreciated!
primer <- function(input_string){
last_position <- nchar(input_string)
output <- ""
for (position in 1:last_position) {
one_character <- substr(input_string, position, position)
if(one_character=="A"){
new_character <- "T" }
if (one_character=="T"){
new_character <- "A"}
if (one_character=="G"){
new_character <- "C"}
if (one_character=="C"){
new_character <- "G"}
output <- paste(new_character, output, sep="")
return(output)
}
}