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

______________________________________________
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.

Reply via email to