Um, maybe just

dat1$C <- match(dat1$B, unique(dat1$B))

Indexing 1:k with numbers between 1 and k is a bit of a no-op...

AFAICT, this even works without stringsAsFactors=FALSE

-pd

> On 11 May 2018, at 21:30 , MacQueen, Don <macque...@llnl.gov> wrote:
> 
> dat1$C <- seq(length(unique(dat1$B)))[ match( dat1$B, unique(dat1$B) )]

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd....@cbs.dk  Priv: pda...@gmail.com

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
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.

Reply via email to