[R] combining columns into a "combination index" of the same length

Thierry Onkelinx thierry.onkelinx at inbo.be
Tue Jul 21 15:32:57 CEST 2015


Yes. paste0() can work on vectors. So paste0(mat[, col1], mat[, col2])

ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to say
what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does not
ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

2015-07-21 15:21 GMT+02:00 Emmanuel Levy <emmanuel.levy op gmail.com>:

> Hi,
>
> The answer to this is probably straightforward, I have a dataframe and I'd
> like to build an index of column combinations, e.g.
>
> col1 col2  --> col3 (the index I need)
> A     1           1
> A     1           1
> A     2           2
> B     1           3
> B     2           4
> B     2           4
>
>
> At the moment I use:
> col3 <- apply(mat[,sel.col], 1, paste0)
>
> But I wonder if another approach could be faster?
>
> Thanks,
>
> Emmanuel
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help op 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.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list