Titus von der Malsburg wrote:
On Tue, Jun 09, 2009 at 11:23:36AM +0200, ONKELINX, Thierry wrote:
For factors, you better convert them first back to character strings.
splice <- function(x, y) {
x <- levels(x)[x]
y <- levels(y)[y]
factor(as.vector(rbind(x, y)))
}
T
On Tue, Jun 9, 2009 at 11:16 AM, Titus von der Malsburg
wrote:
> On Tue, Jun 09, 2009 at 11:04:03AM -0400, Stavros Macrakis wrote:
> > This may seem like a minor point, but I think it is worthwhile using
> > descriptive names for functions.
>
> Makes sense. I thought I've seen this use somewhere
On Tue, Jun 09, 2009 at 11:04:03AM -0400, Stavros Macrakis wrote:
> This may seem like a minor point, but I think it is worthwhile using
> descriptive names for functions.
Makes sense. I thought I've seen this use somewhere else (probably in
Lisp?). What better name do you suggest for this opera
Various people have provided technical solutions to your problem.
May I suggest, though, that 'splice' isn't quite the right word for this
operation? Splicing two pieces of rope / movie film / audio tape / wires /
etc. means connecting them at their ends, either at an extremity or in the
middle,
On Tue, Jun 09, 2009 at 11:23:36AM +0200, ONKELINX, Thierry wrote:
> For factors, you better convert them first back to character strings.
>
> splice <- function(x, y) {
> x <- levels(x)[x]
> y <- levels(y)[y]
> factor(as.vector(rbind(x, y)))
> }
Thank you very much, Thierr
Titus von der Malsburg gmail.com> writes:
> An operation that I often need is splicing two vectors:
> > splice(1:3, 4:6)
> [1] 1 4 2 5 3 6
> For numeric vectors I use this hack:
> splice <- function(x, y) {
> xy <- cbind(x, y)
> xy <- t(xy)
> dim(xy) <- length(x) * 2
> retur
lp-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
Namens Titus von der Malsburg
Verzonden: dinsdag 9 juni 2009 11:12
Aan: r-help@r-project.org
Onderwerp: [R] Splicing factors without losing levels
Hi list!
An operation that I often need is splicing two vectors:
> splice(1:3, 4:6)
Hi list!
An operation that I often need is splicing two vectors:
> splice(1:3, 4:6)
[1] 1 4 2 5 3 6
For numeric vectors I use this hack:
splice <- function(x, y) {
xy <- cbind(x, y)
xy <- t(xy)
dim(xy) <- length(x) * 2
return(xy)
}
So far, so good (?). But I also need
8 matches
Mail list logo