[R] Deleting rows with special character

John Kane jrkrideau at inbox.com
Fri Nov 16 15:35:38 CET 2012


thanks

John Kane
Kingston ON Canada


> -----Original Message-----
> From: peter.kupfer at me.com
> Sent: Fri, 16 Nov 2012 15:32:23 +0100
> To: sarah.goslee at gmail.com
> Subject: Re: [R] Deleting rows with special character
> 
> Hey Sara,
> first: Thanks for the fast reply! I checked the apply function and I
> found my error.
> For sure: I forgot to send an sample data. After sending the mail I
> recognized it. Sorry about this!
> Once again: Thanks for the fast reply and your help.
> Best
> Peter
> 
> 
> 
> Am 16.11.2012 um 15:26 schrieb Sarah Goslee <sarah.goslee at gmail.com>:
> 
>> Hi Peter,
>> 
>> On Fri, Nov 16, 2012 at 9:04 AM, Peter Kupfer <peter.kupfer at me.com>
>> wrote:
>>> Dear all,
>>> maybe a simple problem but I found no solution for my problem.
>>> I have a matrix Y with 23 000 rows and 220 colums. The entries are "A",
>>> "B" or "C".
>> 
>> A reproducible example with sample data is helpful.
>> 
>>> I want to extract all rows (as a matrix ) of the matrix Y where all
>>> entries of a row are (for example) "A".
>> 
>> Really? Why not just make a new matrix with the right number of "A"
>> values?
>> 
>>> Is there any solution? I tried the stringr- package but i doesn't work
>>> out.
>> 
>> Of course there is. Here's one option. But I'm not sure you've really
>> stated your actual problem. This extracts the rows where all values
>> are "A", and might at least get you started toward your real problem.
>> 
>> testdata <- matrix(c(
>> "A", "B", "C",
>> "B", "B", "B",
>> "C", "A", "A",
>> "A", "A", "A"),
>> ncol=3, byrow=TRUE)
>> 
>> testdata.A <- testdata[apply(testdata, 1, function(x)all(x == "A")), ,
>> drop=FALSE]
>> 
>> 
>> 
>> --
>> Sarah Goslee
>> http://www.functionaldiversity.org
> 
> ______________________________________________
> R-help at 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.

____________________________________________________________
GET FREE SMILEYS FOR YOUR IM & EMAIL - Learn more at http://www.inbox.com/smileys
Works with AIM®, MSN® Messenger, Yahoo!® Messenger, ICQ®, Google Talk™ and most webmails




More information about the R-help mailing list