counting duplication

2 views
Skip to first unread message

Lauren Hodgson

unread,
Sep 27, 2012, 1:46:16 AM9/27/12
to tropi...@googlegroups.com
Hi all,

Fastest way to find number of times a number is duplicated in a column
of a data frame???

Hint: it's not running a for loop that iterates through 30 000 unique
values of the duplicates, lol.

It's like a horrible game - answer before my stupid loop completes.


Not the answer:

duplicates=mydata$values.with.duplicates[duplicated(mydata$values.with.duplicates)]

mydata$times.duplicated=1

for (dup in duplicates) {
tt=length(mydata$values.with.duplicates[which(mydata$values.with.duplicates==dup)])
mydata$times.duplicated[which(mydata$values.with.duplicates==dup)]=tt
}

Keith, Sally

unread,
Sep 27, 2012, 1:48:40 AM9/27/12
to tropi...@googlegroups.com
table(mydata$columnname)
--
An R group for questions, tips and tricks relevant to spatial ecology and climate change.
All R questions welcome.
---
You received this message because you are subscribed to the Google Groups "Tropical R" group.
To post to this group, send an email to tropi...@googlegroups.com.
To unsubscribe from this group, send email to tropical-r+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.




Lauren Hodgson

unread,
Sep 27, 2012, 2:00:27 AM9/27/12
to tropi...@googlegroups.com
hahaha, awesome! thanks so much.

as.data.frame(table(mydata$columnname)) allows me to merge this info
to the main data frame.
Reply all
Reply to author
Forward
0 new messages