[R] Conditional values of a vector XXXX

From: Dan Abner <dan.abner99_at_gmail.com>
Date: Sun, 08 May 2011 19:20:50 -0400

Hello everyone,

Below is a metadata summary of raw data in a data frame (which itself is a data frame). I want to add 2 columns to the data frame below that will contain the min and max for integer and numeric class columns and NA for factors and character vectors. Can anyone suggestion the most succinct way of going about this?

  Variable Class Mode

1       id integer numeric
2       x1 numeric numeric
3       x2 numeric numeric
4       x3 numeric numeric
5        y numeric numeric

6 gender factor numeric
7 char1 factor numeric
I have the following, but it does not work:


I receive the following:

> x.contents.3<-data.frame(id=1:ncol(x),Min=NA,Max=NA,row.names="id")
> x.contents.3[!(x.contents.2$Class("factor","character")),1]<-sapply(x,min)
Error in Summary.factor(c(1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, :   min not meaningful for factors
> x.contents.3[!(x.contents.2$Class("factor","character")),2]<-sapply(x,max)
Error in Summary.factor(c(1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, :   max not meaningful for factors



        [[alternative HTML version deleted]]

R-help_at_r-project.org mailing list
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. Received on Sun 08 May 2011 - 23:30:47 GMT

This quarter's messages: by month, or sorted: [ by date ] [ by thread ] [ by subject ] [ by author ]

All messages

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sun 08 May 2011 - 23:40:05 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive