Hi, I would like to count the columns of a data.frame. I know how to count the rows, but not the columns. Can someone tell me how to do it? My best regards, Giacomo Moro --------------------------------- [[alternative HTML version deleted]]
giacomo moro wrote:> > I would like to count the columns of a data.frame. I know how to > count the rows, but not the columns. Can someone tell me how to do > it?ncol(data.frame) -- Ram?n Casero Ca?as http://www.robots.ox.ac.uk/~rcasero/wiki http://www.robots.ox.ac.uk/~rcasero/blog
> da<-data.frame(x=rnorm(10),y=rnorm(10)) > ncol(da)[1] 2 or> dim(da)[2][1] 2 2006/4/15, giacomo moro <gmbegnis at yahoo.it>:> Hi, > I would like to count the columns of a data.frame. I know how to count the rows, but not the columns. > Can someone tell me how to do it? > My best regards, > Giacomo Moro > > > > --------------------------------- > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- ?????? Deparment of Sociology Fudan University
?ncol ncol(data.frame(x=-1, y=0, z=1)) [1] 3 giacomo moro wrote:> Hi, > I would like to count the columns of a data.frame. I know how to count the rows, but not the columns. > Can someone tell me how to do it? > My best regards, > Giacomo Moro > > > > --------------------------------- > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html >-- Chuck Cleland, Ph.D. NDRI, Inc. 71 West 23rd Street, 8th floor New York, NY 10010 tel: (212) 845-4495 (Tu, Th) tel: (732) 512-0171 (M, W, F) fax: (917) 438-0894
> > Hi, > I would like to count the columns of a data.frame. I know > how to count the rows, but not the columns.... If you knew how to count the rows, you would have known about nrow which has the same man page as ncol. Also help.search('number of rows') would have immediately given you your answers. So please do your homework before posting in future by using R's extensive built-in documentation. -- Bert Gunter