On 28.01.2012 05:43, Melissa Patrician wrote:
Hi, Please excuse my inexperience, but I am just learning R (this is my very first day programming in R) and having a really hard time figuring out how to do the following: I have a matrix that is 1000 row by 6 columns (named 'table.combos') and a 1 row by 6 column vector (named 'mine'). I want to find every row in 'table.combos' that equals 'mine' and then count this number of times that this is the case. In matlab, I would use the 'find' command but I can not seem to figure out what syntax to use for R. Can anyone please help? Again, I'm assuming this is probably a very easy thing to do, but since I am new to R, I am having a hard time figuring it out. I did some research on previous posts and saw that the 'apply' function appears to do something like this, but I don't know what function I am supposed to input into 'apply' to use this.
If you like the apply way, you have a vector v and your matrix M: sum(apply(table.combos, 1, function(x) all(x == mine))) Uwe Ligges
Thanks in advance for the help! Cheers, Melissa
______________________________________________ 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.