[R] Simple question on finding duplicates
gunter.berton at gene.com
Wed Jul 25 22:28:16 CEST 2012
On Wed, Jul 25, 2012 at 1:22 PM, David L Carlson <dcarlson at tamu.edu> wrote:
> duplicate <- ifelse(c(0, a$col[-length(a$col)])==c(a$col), 1, 0)
> David L Carlson
> Associate Professor of Anthropology
> Texas A&M University
> College Station, TX 77843-4352
>> -----Original Message-----
>> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
>> project.org] On Behalf Of Jeff
>> Sent: Wednesday, July 25, 2012 3:06 PM
>> To: r-help at r-project.org
>> Subject: [R] Simple question on finding duplicates
>> I'm trying to find duplicate values in a column of a data frame.
>> 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
>> 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?
>> 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
>> PLEASE do read the posting guide http://www.R-project.org/posting-
>> and provide commented, minimal, self-contained, reproducible code.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Genentech Nonclinical Biostatistics
Internal Contact Info:
More information about the R-help