[R] ncol() vs. length() on data.frames

Eric Berger er|cjberger @end|ng |rom gm@||@com
Tue Mar 31 15:39:19 CEST 2020


Yes it does because length(list) gives you the number of elements of the
list. And in the case of a data frame object that is the number of columns,
or ncol().

On Tue, Mar 31, 2020 at 4:37 PM Ivan Calandra <calandra using rgzm.de> wrote:

> Thanks Eric,
>
> I know that, but that doesn't really answer my question, does it?
>
> Ivan
>
> --
> Dr. Ivan Calandra
> TraCEr, laboratory for Traceology and Controlled Experiments
> MONREPOS Archaeological Research Centre and
> Museum for Human Behavioural Evolution
> Schloss Monrepos
> 56567 Neuwied, Germany
> +49 (0) 2631 9772-243
> https://www.researchgate.net/profile/Ivan_Calandra
>
> On 31/03/2020 15:26, Eric Berger wrote:
> > A data frame is a special case of a list. It is a list of its columns.
> >
> > > is.list( your_data_frame )
> >
> > # TRUE
> >
> >
> > On Tue, Mar 31, 2020 at 4:04 PM Ivan Calandra <calandra using rgzm.de
> > <mailto:calandra using rgzm.de>> wrote:
> >
> >     Dear useRs,
> >
> >     I have a very simple question:
> >     On a simple data.frame (i.e. each element is a vector), ncol() and
> >     length() will give the same result.
> >
> >     Are they just equivalent on such objects, or are they differences in
> >     some cases?
> >     Is one of them to be preferred for whatever reason?
> >
> >     Thanks you,
> >     Ivan
> >
> >     --
> >     Dr. Ivan Calandra
> >     TraCEr, laboratory for Traceology and Controlled Experiments
> >     MONREPOS Archaeological Research Centre and
> >     Museum for Human Behavioural Evolution
> >     Schloss Monrepos
> >     56567 Neuwied, Germany
> >     +49 (0) 2631 9772-243
> >     https://www.researchgate.net/profile/Ivan_Calandra
> >
> >     ______________________________________________
> >     R-help using r-project.org <mailto:R-help using 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.
> >
>
> ______________________________________________
> R-help using 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