I think this is the s2c function OP is using. Also, how is a[8] == "T"||"A" even proper R syntax? the "T" || "A" will throw an error. Pretty sure OP's code doesn't work as-is at the moment.
Can you describe what you're trying to achieve and what a actually looks like (i.e., the result of s2c(at)).
EDIT: and what the final for-loop is supposed to achieve.
I promise, if you describe your question properly (i.e. what exactly should be the end result?) there's going to be a more robust way of doing that in R.
I want to match the position of each sequences w.r.t. each other
For example, if A or T is present in "11th or 17" location of each sequence then return 1 else 0.
That seems to be partially from multiple sequence alignment, Either way, you might benefit from creating a 2D matrix with each column a base position and each row a sequence, that would be a lot easier to filter using indexes.
Please use ADD COMMENT/ADD REPLY when responding to existing posts to keep threads logically organized.
SUBMIT ANSWER is for new answers to original question.
Ideally edit your original question and add this information there.
To simplify your example, condition: if any 2nd or 4th position in every sequence has A or T, then TRUE.
# example data
x <- c("AAGTA",
"AAGTA",
"AAGTA",
"ACGAA")
# in this example all TRUE
all(substr(x, 2, 2) %in% c("A", "T") | substr(x, 4, 4) %in% c("A", "T"))
# [1] TRUE
If this is not the solution you are looking for, then please provide example input and expected output, clearly.
assuming this is R code, I don't think that the command works even in a single instance outside a for-loop:
> "A" == "T"||"A" && "A" == "A"||"T"
Error in "A" && "A" == "A" : invalid 'x' type in 'x && y'
The syntax would have to be:
> "A" %in% c("T","A") && "A" %in% c("T","A")
[1] TRUE
That being said, as the numerous comments above indicate, there's most definitely a more straight-forward way of doing whatever it is you're trying to do.
This is a Question, not a Page, please be careful when selecting the post type.
What is
s2c()
? From which package?If the code above works but the loop doesn't, you should show the loop as well, and provide an example dataset to replicate the failure.
This looks like code directly translated from Excel functions. Surely there must be better, more efficient ways to achieve OP's goals.
I think this is the s2c function OP is using. Also, how is
a[8] == "T"||"A"
even proper R syntax? the"T" || "A"
will throw an error. Pretty sure OP's code doesn't work as-is at the moment.Can you describe what you're trying to achieve and what
a
actually looks like (i.e., the result ofs2c(at)
).EDIT: and what the final for-loop is supposed to achieve.
I promise, if you describe your question properly (i.e. what exactly should be the end result?) there's going to be a more robust way of doing that in R.
that "a" I was using for next coding step; not the part of this analysis.
Thanks, everyone for reply.
Let me correct my question to make it easy to understand
I have a list of sequences like this in 2nd column of a csv file.
I want to match the position of each sequences w.r.t. each other For example, if A or T is present in "11th or 17" location of each sequence then return 1 else 0.
Thanks in advance
That seems to be partially from multiple sequence alignment, Either way, you might benefit from creating a 2D matrix with each column a base position and each row a sequence, that would be a lot easier to filter using indexes.
Please use
ADD COMMENT/ADD REPLY
when responding to existing posts to keep threads logically organized.SUBMIT ANSWER
is for new answers to original question.Ideally edit your original question and add this information there.
That doesn't make sense to me.
Do you only care about the presence or absence in certain positions? How many positions are you interested in?