s-news
[Top] [All Lists]

SUMMARY: Concatenating random number of random length vectors

To: "S-plus list (S-plus list)" <s-news@wubios.wustl.edu>
Subject: SUMMARY: Concatenating random number of random length vectors
From: "P.J.Wells" <P.J.Wells@open.ac.uk>
Date: Thu, 27 Mar 2003 17:25:32 -0000
Many thanks to those who replied -- I am well and truly kick-started!

A) As already posted to the list, Sundar Dorai-Raj suggested:

1) `for':
# assume each vector is named `sample.i'
# where `i' is 1:N
samp <- c()
for(i in 1:N)
   samp <- c(samp, get(paste("sample", i, sep = ".")))

I'd tried various schemes involving for(), but had forgotten get(), so I
think Sundar gets the mind-reading prize.

2) `do.call':
# assume your N samples are in a list `samp.list'
# where length(samp.list) == N
samp <- do.call("c", samp.list)

This also came from Brian Ripley.


B) Naomi Altman also pointed out a simple scheme, given a list of the
samples:

unlist(sample.list)


C) Jean Adams and Bert Gunter both suggested using collapse(), given N

eval(parse(text=paste('c(',paste('sample',1:N,sep='.',collapse=','),')',sep=
'')))


D) Winnie Lambert reminded me that append() would also do the trick.

Julian Wells

School of Management
The Open University
Walton Hall
Milton Keynes
MK7 6AA
United Kingdom

(01908) 654658
+44 (1908) 654658 

<Prev in Thread] Current Thread [Next in Thread>
  • SUMMARY: Concatenating random number of random length vectors, P.J.Wells <=