Hi, Is the following function built in somewhere? concat = function(v) { res = "" for (i in 1:length(v)) res = paste(res,v[i],sep="") res } e.g. > concat(c("12","3","45")) [1] "12345" Cheers, Andy -- Andy Fugard, Postgraduate Research Student Psychology (Room F3), The University of Edinburgh, 7 George Square, Edinburgh EH8 9JZ, UK Mobile: +44 (0)78 123 87190 http://www.possibly.me.uk The University of Edinburgh is a charitable body, registered in Scotland, with registration number SC005336.
Hi, Andy I am a little confused, why don't you just use paste() directly? > paste("12","3","45",sep="") produce the same result with your concat. regards . On 2008-6-28, at ??7:44, Andy Fugard wrote:> Hi, > > Is the following function built in somewhere? > > concat = function(v) { > res = "" > > for (i in 1:length(v)) > res = paste(res,v[i],sep="") > > res > } > > e.g. > > > concat(c("12","3","45")) > [1] "12345" > > Cheers, > > Andy > > -- > Andy Fugard, Postgraduate Research Student > Psychology (Room F3), The University of Edinburgh, > 7 George Square, Edinburgh EH8 9JZ, UK > Mobile: +44 (0)78 123 87190 http://www.possibly.me.uk > > The University of Edinburgh is a charitable body, registered in > Scotland, with registration number SC005336. > > ______________________________________________ > R-help at r-project.org mailing list > 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.----------------------------------------------- Peng Jiang ?? Ph.D. Candidate Antai College of Economics & Management ???????? Department of Mathematics ??? Shanghai Jiaotong University (Minhang Campus) 800 Dongchuan Road 200240 Shanghai P. R. China
paste(v, collapse="") On Sat, 28 Jun 2008, Andy Fugard wrote:> Hi, > > Is the following function built in somewhere? > > concat = function(v) { > res = "" > > for (i in 1:length(v)) > res = paste(res,v[i],sep="") > > res > } > > e.g. > >> concat(c("12","3","45")) > [1] "12345" > > Cheers, > > Andy > > -- > Andy Fugard, Postgraduate Research Student > Psychology (Room F3), The University of Edinburgh, > 7 George Square, Edinburgh EH8 9JZ, UK > Mobile: +44 (0)78 123 87190 http://www.possibly.me.uk > > The University of Edinburgh is a charitable body, registered in > Scotland, with registration number SC005336. > > ______________________________________________ > R-help at r-project.org mailing list > 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. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595