[R] apply min function rowwise
Joshua Wiley
jwiley.psych at gmail.com
Sat Jun 5 18:30:46 CEST 2010
Hello M,
My guess is that it has something to do with the class of the
variables. Perhaps you could provide a small sample dataframe? Also
you might try running str() on your data frame and seeing if the
results are what you would expect. As a side note, it is not
necessary to make an anonymous function here, as you are allowed to
pass arguments to the function applied.
apply(canc[,vec],1, min, na.rm=TRUE)
Best regards,
Josh
On Sat, Jun 5, 2010 at 8:30 AM, moleps <moleps2 at gmail.com> wrote:
> I´m trying to tease out the minimum value from a row in a dataframe where all the variables are dates.
>
> apply(canc[,vec],1,function(x)min(x,na.rm=T))
>
>
> However it only returns empty strings for the entire dataframe except for one date value (which is not the minimum date).
>
> I´ve also tried
>
> apply(canc[,vec],1,function(x)max(x,na.rm=T))
>
> which provides values rowwise, but many of them are not in fact the largest in the row.
>
>
> Any advice?
>
>
> Regards,
>
> //M
>
> ______________________________________________
> 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.
>
--
Joshua Wiley
Senior in Psychology
University of California, Riverside
http://www.joshuawiley.com/
More information about the R-help
mailing list