loop for a large database
On Feb 26, 2012, at 7:13 AM, mari681 wrote:
Yes, I am a newbie. I have a data.frame (MyTable) of 1445846 rows and 15 columns with character data. And a character vector (MyVector) of 473491 elements. I want simply to get a data.frame with the count of how many times each element of MyVector appears in MyTable. I've tried a loop with : for (i in 1 : length (myvector)) sum (MyTable== i)
In that instance "i" is a number and probably would not be matching something that was a character vector.
but it crashes my computer.
I've also tried something like
x <- 1 : length (MyVector)
apply (MyTable , 1 , function(x) {sum (MyTable ==x)}
but doesn't work.
Any idea?
Thank you. AAAAAny suggestion is super welcome.
Since you never offered the requested information about your objects, this is guesswork. If MyVector is one of the 15 columns in MyTable then this will have good chance: table(MyTable$MyVector) If on the other hand they are separate and you want to ignore the elements not in MyVector, then assign the value of a table operation and then use match() to pick out the tabulated values In the future, please al least offer the results of str(MyTable).
David Winsemius, MD Heritage Laboratories West Hartford, CT