[R] for (i in ...) { df[[i]]<- .....}
Prof Brian Ripley
ripley at stats.ox.ac.uk
Fri Aug 27 15:31:44 CEST 2004
PLEASE don't call methods explicitly.
I think
do.call("cbind", cc)
is what you are looking for, although probably you should be calling
data.frame not cbind here. (Your lines are too long and contain no spaces
so I am not going to try to fathom out what cc[[i]] really is. But I am
sure you do not intend the cbind to be inside the loop.)
On Fri, 27 Aug 2004, Luis Rideau Cruz wrote:
> In the following loop :
>
> for(i in 1:8)
> {
> cc[[i]]<-tapply(test[,i+6],list(puntar=test$puntar),sum)/tapply(test[,5],list(puntar=test$puntar),sum)
>
> cbind.data.frame(cc[[1]],cc[[2]],cc[[3]],cc[[4]],
> cc[[5]],c[[6]],cc[[7]],cc[[8]])
>
> }
>
> Is there anyway I can 'cbind.data.frame' the objects cc[[ i ]] without
> actually writing every single element??
> In this case there are 8 but what if it is a large number??
--
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
More information about the R-help
mailing list