[R] duplicated() with long vectors
Stephen Politzer-Ahles
politzerahless at gmail.com
Wed Dec 5 21:53:56 CET 2012
Hello,
duplicated() does not seem to work for a long vector. For example, if
you download the data from
https://docs.google.com/open?id=0B6-m45Jvl3ZmNmpaSlJWMXo5bmc (a vector
with about 12,000 numbers) and then run the following code which does
duplicated() over the whole vector but just shows the last 30
elements:
data.frame( tail(verylong, 30), tail(duplicated(verylong), 30) )
you'll see that at the end of the very long vector everything is
listed as a duplicate of the preceding element (even though it
shouldn't be). On the other hand, if you run the following code which
just takes out the last 30 elements of the vector and does duplicated
on them:
data.frame( tail(verylong, 30), duplicated(tail(verylong, 30)) )
you get the correct results (FALSE shows up wherever the value in the
first column changes). Does anyone know why this happens, and if
there's a fix? I notice the documentation for duplicated() says: "Long
vectors are supported for the default method of duplicated, but may
only be usable if nmax is supplied." But I've tried running this with
a high value of nmax given, and it still gives me the same problem.
So far the only way I've figured out to get this duplicated()-like
vector is to use a for loop going through one item at a time, but that
takes about a minute to run.
Best,
Steve Politzer-Ahles
--
Stephen Politzer-Ahles
University of Kansas
Linguistics Department
http://people.ku.edu/~sjpa/
More information about the R-help
mailing list