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 . 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 "What is expressed without proof can be denied without proof" - Euclide. Please visit us at www.itcportal.com ****************************************************************************** This Communication is for the exclusive use of the intended recipient (s) and shall not attach any liability on the originator or ITC Ltd./its Subsidiaries/its Group Companies. If you are the addressee, the contents of this email are intended for your use only and it shall not be forwarded to any third party, without first obtaining written authorisation from the originator or ITC Ltd./its Subsidiaries/its Group Companies. It may contain information which is confidential and legally privileged and the same shall not be used or dealt with by any third party in any manner whatsoever without the specific consent of ITC Ltd./its Subsidiaries/its Group Companies. [[alternative HTML version deleted]]
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