s-news
[Top] [All Lists]

Tricky Merging of a vector and a list

To: s-news@lists.biostat.wustl.edu
Subject: Tricky Merging of a vector and a list
From: Sven.Knudsen@adeptscience.dk
Date: Thu, 20 Mar 2003 11:02:18 +0100
Hi S-friends

I have a small, but to me tricky problem.

Let a denote a list, say
> a <- list()
> a$n1 <- 1:2
> a$n2 <- 3:4
> a
$n1:
[1] 1 2

$n2:
[1] 3 4

Let b denote a vector of same length as a, and assume that

>b <- c(0,12)

I know want to create the following merged list of a and b, consisting of a
   [[i]] <- c(b[i],a[[i]])
> a
$n1:
[1] 0 1 2

$n2:
[1] 12  3  4

No problems in using a loop - but my list's are very long.

Any suggestions to avoid a loop will be appreciated

Kind regards

Sven
Adept Scientific Aps



<Prev in Thread] Current Thread [Next in Thread>
  • Tricky Merging of a vector and a list, Sven . Knudsen <=