Re: [R] R: cbind

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Mon 08 Aug 2005 - 21:36:33 EST

On 8/8/05, Clark Allan <Allan@stats.uct.ac.za> wrote:
> hi all
>
>
> are we able to combine column vectors of different lengths such that the
> result appears in matrix form?
>
> e.g.
>
> a=1
> b=1:3
> d=1:4
>
> then
>
> z=CBIND(a,b,d)
>
>
> 1 1 1
> 2 2
> 3 3
> 4
>
> i stil want the following!
> z[,1]=1
> z[,2]=1:3
> z[,3]=1:5
>
> i made up the name of this function. we could use "cbind" but it does
> not seem to allows this!

There are a number of alternatives:

# 1. just create a list

x1 <- list(a = 1, b = 1:3, c = 1:4)

# 2. create a ts object:

x2 <- do.call("cbind", lapply(x1, ts))

# 3. create a matrix from the ts object

x3 <- unclass(do.call("cbind", lapply(d, ts))) tsp(x3) <- NULL



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Aug 08 21:40:45 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:45 EST