Vitrifizierung
2011-Apr-13 11:17 UTC
[R] Find characters in a matrix and return a TRUE-FALSE vector
I have the following problem: My data is a matrix of multiple columns and rows. The column I am interested in looks like that (I think it is a column in a matrix that contains a vector each?): [[1]] [1] A B C [4] D E [[2]] [1] A D E [[3]] [1] C E F [4] G I now want to look for a special word (for example C; in my case the single entries are words, not single letters) and return a vector, like [1] TRUE FALSE TRUE Is there an easy way to do it? Sorry, I am really a beginner and I did not really solve the problem by looking into other threads... Thanks a lot, Nina -- View this message in context: http://r.789695.n4.nabble.com/Find-characters-in-a-matrix-and-return-a-TRUE-FALSE-vector-tp3446868p3446868.html Sent from the R help mailing list archive at Nabble.com.
Jorge Ivan Velez
2011-Apr-13 14:32 UTC
[R] Find characters in a matrix and return a TRUE-FALSE vector
Hi Nina, You might try sapply(yourdata, function(x) any(x == "C")) See ?sapply for more details. HTH, Jorge On Wed, Apr 13, 2011 at 7:17 AM, Vitrifizierung <> wrote:> I have the following problem: > > My data is a matrix of multiple columns and rows. The column I am > interested > in looks like that (I think it is a column in a matrix that contains a > vector each?): > > [[1]] > [1] A B C > [4] D E > > [[2]] > [1] A D E > > [[3]] > [1] C E F > [4] G > > I now want to look for a special word (for example C; in my case the single > entries are words, not single letters) and return a vector, like > > [1] TRUE FALSE TRUE > > Is there an easy way to do it? > Sorry, I am really a beginner and I did not really solve the problem by > looking into other threads... > > Thanks a lot, > Nina > > -- > View this message in context: > http://r.789695.n4.nabble.com/Find-characters-in-a-matrix-and-return-a-TRUE-FALSE-vector-tp3446868p3446868.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > 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. >[[alternative HTML version deleted]]