Dear Phillip,
Your example suggests that the rows with duplicate names are contiguous. If
this is the case, then the following should do what you want without using
a lot of memory (where df is the data frame):
rows <- c("",row.names(df))
keep <- 1:nrow(df)
for (i in 1:nrow(df)) if (rows[i+1] == rows[i]) keep[i] <- 0
df <- df[keep,]
I hope that this helps,
John
At 12:33 AM 1/19/2003 -0700, Phillip Staford wrote:
Dear S group;
I'm looking for a very low-memory (slow is OK, but memory is critical
here) method to collapse a data.frame that has a mixture of unique and
replicated row.names. What's the best way to do this without burning
unnecessary memory?
A 3
A 2
A 1
B 3
C 2
C 4
into
A 2
B 3
C 3
Thanks for any suggestions, the obvious ways are quick but not memory
efficient I think.
-----------------------------------------------------
John Fox
Department of Sociology
McMaster University
Hamilton, Ontario, Canada L8S 4M4
email: jfox@mcmaster.ca
phone: 905-525-9140x23604
web: www.socsci.mcmaster.ca/jfox
-----------------------------------------------------
|