[R] Fwd: which is faster "for" or "apply"
Karim Mezhoud
kmezhoud at gmail.com
Wed Dec 31 09:22:58 CET 2014
Thanks,
It seems for loop spends less time ;)
with
dim(DataFrame)
[1] 338 70
For loop has
user system elapsed
0.012 0.000 0.012
and apply has
user system elapsed
0.020 0.000 0.021
Ô__
c/ /'_;~~~~kmezhoud
(*) \(*) ⴽⴰⵔⵉⵎ ⵎⴻⵣⵀⵓⴷ
http://bioinformatics.tn/
On Wed, Dec 31, 2014 at 8:54 AM, Berend Hasselman <bhh at xs4all.nl> wrote:
>
> > On 31-12-2014, at 08:40, Karim Mezhoud <kmezhoud at gmail.com> wrote:
> >
> > Hi All,
> > I would like to choice between these two data frame convert. which is
> > faster?
> >
> > for(i in 1:ncol(DataFrame)){
> >
> > DataFrame[,i] <- as.numeric(DataFrame[,i])
> > }
> >
> >
> > OR
> >
> > DataFrame <- as.data.frame(apply(DataFrame,2 ,function(x) as.numeric(x)))
> >
> >
>
> Try it and use system.time.
>
> Berend
>
> > Thanks
> > Karim
> > Ô__
> > c/ /'_;~~~~kmezhoud
> > (*) \(*) ⴽⴰⵔⵉⵎ ⵎⴻⵣⵀⵓⴷ
> > http://bioinformatics.tn/
> >
> > [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > 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.
>
>
[[alternative HTML version deleted]]
More information about the R-help
mailing list