[R] add one variable to a data frame
MacQueen, Don
m@cqueen1 @end|ng |rom ||n|@gov
Sat May 12 01:22:02 CEST 2018
Of course...
Thanks
-Don
--
Don MacQueen
Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062
Lab cell 925-724-7509
On 5/11/18, 3:50 PM, "R-help on behalf of peter dalgaard" <r-help-bounces using r-project.org on behalf of pdalgd using gmail.com> wrote:
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 <macqueen1 using 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.mes using cbs.dk Priv: PDalgd using gmail.com
______________________________________________
R-help using 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.
More information about the R-help
mailing list