Hi I try to create from a data frame a new one which contains only the numerical variables (or factorial ones). Is there any function which does this task directly ? Or, is there any function which return the mode of each columns of a data frame. ? Thanks a lot for any help you can offer me, Vincent Spiesser
On Fri, 29 Aug 2003, Vincent Spiesser wrote:> Hi > > I try to create from a data frame a new one which contains only the > numerical variables (or factorial ones). > > Is there any function which does this task directly ? > Or, is there any function which return the mode of each columns of a data > frame. ?I think you want the class, as in sapply(adf, class) You could use mode if you really wanted it, but watch out for e.g. the mode of a factor being "numeric". However, for your original question I would use numeric columns: DF[sapply(DF, is.numeric)] factor columns: DF[sapply(DF, is.factor)] and similar code is found throughout the R sources. -- 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
for data.frame called dframe: newframe <- dframe[ , lapply(dframe, is.numeric)] For the mode of the columns lapply(dframe, mode) See ?lapply !!> -----Original Message----- > From: Vincent Spiesser [mailto:Vincent.Spiesser at univ-tlse1.fr] > Sent: 29 August 2003 10:08 > To: R-help at stat.math.ethz.ch > Subject: [R] extract numerical variables from a data frame > > > Security Warning: > If you are not sure an attachment is safe to open please contact > Andy on x234. There are 0 attachments with this message. > ________________________________________________________________ > > Hi > > I try to create from a data frame a new one which contains only the > numerical variables (or factorial ones). > > Is there any function which does this task directly ? > Or, is there any function which return the mode of each columns of a > data > frame. ? > > Thanks a lot for any help you can offer me, > > Vincent Spiesser > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help >Simon Fear Senior Statistician Syne qua non Ltd Tel: +44 (0) 1379 644449 Fax: +44 (0) 1379 644445 email: Simon.Fear at synequanon.com web: http://www.synequanon.com Number of attachments included with this message: 0 This message (and any associated files) is confidential and\...{{dropped}}