Skip to content
Prev 181104 / 398503 Next

Loop avoidance and logical subscripts

On 21-May-09 16:56:23, retama wrote:
Perhaps the following could be the basis of your code for the bigger
problem:

  S <- unlist(strsplit("AATTCCCGGGGGG",""))
  S
#  [1] "A" "A" "T" "T" "C" "C" "C" "G" "G" "G" "G" "G" "G"
  (sum((S=="C")|(S=="G")))
# [1] 9
  (sum((S=="C")|(S=="G")))/length(S)
# [1] 0.6923077

You could build a function on those lines, to evaluate what you
want for any given string; and then apply() it to the elements
(which are the separate character strings) of data$sequences
(which is presumably a vector of character strings).

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 21-May-09                                       Time: 18:18:24
------------------------------ XFMail ------------------------------