On Tue, 31 Mar 2020 14:47:54 +0200 Ivan Calandra <calan...@rgzm.de> wrote:
> 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? I am not aware of any exceptions to ncol(dataframe)==length(dataframe) (in fact, ncol(x) is dim(x)[2L] and ?dim says that dim(dataframe) returns c(length(attr(dataframe, 'row.names')), length(dataframe))), but watch out for AsIs columns which can have columns of their own: x <- data.frame(I(volcano)) dim(x) # [1] 87 1 length(x) # [1] 1 dim(x[,1]) # [1] 87 61 -- Best regards, Ivan ______________________________________________ R-help@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.