Skip to content
Back to formatted view

Raw Message

Message-ID: <2CA0DB28-89C0-4DB7-BCD0-87F409789791@comcast.net>
Date: 2012-02-14T06:40:34Z
From: David Winsemius
Subject: help with matrix column cleaning
In-Reply-To: <OFFFDDE0D8.E1D7F509-ON652579A4.001EFBDE-652579A4.001FB7DB@itc.in>

On Feb 14, 2012, at 12:46 AM, Vijayan Padmanabhan wrote:

> Dear R Group
> I have a matrix object in R, where i want to retain only those columns
> which have each row from a different group..
>
> see the example below..
> team1<-c("a1","a2","b1","b2","b3","c1","c2")
>
> teams<-combn(team1, 3)
>
> I want a function which will delete all columns in the teams matrix  
> that
> have more than 1 row having same letter starts..
>
> For instance in the example object teams,  I want to retain column
> 8,11,12,13,14,18,19,21,22,23,24 .

This will give you a logical vector which you can use with "[" in the  
column position to select those columns:


  apply(teams, 2, function(x) length( unique(substr(x, 1,1))) ==3 )

  [1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE FALSE   
TRUE  TRUE
[13]  TRUE  TRUE FALSE FALSE FALSE  TRUE  TRUE FALSE  TRUE  TRUE   
TRUE  TRUE
[25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE

> I am looking at doing this in larger matrix objects using a function
> preferrably that i can apply to the matrix object to check for the
> beginning letter of each cell from each row and delete columns that  
> have
> more than one row having the same start letter.
>
> Thanks for your help.
> Regards
> Vijayan Padmanabhan
>


-- 
David Winsemius, MD
West Hartford, CT