[R] looping through rows of a logical matrix for combination with and testing of a numeric vector

Bert Gunter bgunter.4567 at gmail.com
Thu Dec 3 16:58:00 CET 2015


I should have added -- is this homework? There is a no homework policy
on this list.

Bert Gunter

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
   -- Clifford Stoll


On Thu, Dec 3, 2015 at 7:54 AM, Bert Gunter <bgunter.4567 at gmail.com> wrote:
> Have you spent any time with an R tutorial or two? I ask, because you
> do not seem to have much knowledge of the language and its features.
> Have you made any effort to figure this out yourself? -- if so, show
> us your code and where/how it goes wrong. I ask, because you seem to
> be asking this list to do your work for you, which is not its purpose.
>
> Cheers,
> Bert
>
>
> Bert Gunter
>
> "Data is not information. Information is not knowledge. And knowledge
> is certainly not wisdom."
>    -- Clifford Stoll
>
>
> On Thu, Dec 3, 2015 at 7:28 AM, debra ragland via R-help
> <r-help at r-project.org> wrote:
>> I have read in a sequence alignment and have done the necessary steps to separate and store the elements of the original input into a new list of character vectors. I have compared the sequence list to a "standard" vector, such that the return is a matrix of logical values indicating TRUE if there is a match to the standard and FALSE where there is no match.
>>
>> An example;
>>
>> mylist=c("AAEBCC", "AABDCC", "AABBCD")
>> list.2 <- strsplit(mylist, split=NULL)
>> # setting a standard for comparison
>> std.string <- "AABBCC"
>> standard <- unlist(strsplit(std.string, split=NULL))
>> #create a logical matrix
>> mat<-sapply(list.2, function(x) x==standard)
>>>mat
>>
>>
>> [,1]  [,2]  [,3]
>> [1,]  TRUE  TRUE  TRUE
>> [2,]  TRUE  TRUE  TRUE
>> [3,] FALSE  TRUE  TRUE
>> [4,]  TRUE FALSE  TRUE
>> [5,]  TRUE  TRUE  TRUE
>> [6,]  TRUE  TRUE FALSE
>>
>> Where the number of columns is the same length as the original input strings I compared (15) and the number of rows corresponds is the same as the number of strings from the input (99).
>>
>> I also have a named numeric vector(of length 15)--where the "names" of the the values match those of the columns of the logical matrix. For the example
>>
>> x2 = runif(3, 5.0, 7.5)
>> names(x2) = 1:3
>>> x2
>> 1        2        3
>> 5.352611 7.058169 6.993105
>>
>> For each row in the in the logical matrix I want to combine the logical values with the values from the numeric vector so that I can run a wilcox.test using those values that are "TRUE" against those that are "FALSE".
>>
>> For instance if each row&vector pairing was a mini data.frame it would look like
>>
>> df=data.frame(x2, mat[3,])
>>>df
>> 1 5.352611 FALSE
>> 2 7.058169 TRUE
>> 3 6.993105 TRUE
>> wilcox.test(df) #based on all true values vs. all false values
>>
>> How can this be achieved?
>>
>> ______________________________________________
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> 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.



More information about the R-help mailing list