[R] Simple question on finding duplicates
Peter Ehlers
ehlers at ucalgary.ca
Wed Jul 25 23:14:20 CEST 2012
duplicate <- c(0, diff(a[,"col1"]) == 0)
Peter Ehlers
On 2012-07-25 13:05, Jeff wrote:
>
> I'm trying to find duplicate values in a column of a data frame. For
> example, dataframe (a) below has two 3's. I would like to mark each value of
> each row as either not being a duplicate of the one before (0), or as a
> duplicate (1) - for example, as in dataframe (b). In SPSS, I would simply
> compare each value to it's "lagged" value, but I can't figure out how to do
> this with R.
> Can someone point me in the right direction?
> Thanks
> a <- data.frame( col1 = c(1,2,3,3,4))
> b <- data.frame( col1 = c(1,2,3,3,4), duplicate = c(0,0,0,1,0))
> ______________________________________________
> R-help at 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.
>
More information about the R-help
mailing list