Re: [R] transforming column of a dataframe by var- and median-functions

From: Henrique Dallazuanna <wwwhsd_at_gmail.com>
Date: Sun, 09 Mar 2008 20:31:19 -0300

I think that your 'C' column is a factor(or character), because the character used(comma).

One option:

dat$C <- as.numeric(gsub(",", ".", as.character(dat$C)))

library(doBy)
summaryBy(C ~ B, data=dat, FUN=c(median, var), na.rm = T)

On 09/03/2008, Agrarimmobilien <ralf.pfeiffer_at_agrarimmobilien.info> wrote:
> Hello,
>
> I try to transform a data frame like
>
> A B C
>
> 1 1 2,5
> 2 2 NA
> 3 1 1,0
> 4 1 56
> 5 2 23
> 6 1 NA
> 7 2 46
>
> to the following dataframe, calculating the variance and median of the
> C-column, group by B, so the result will be:
>
> B C(median) D (var)
> 1 19,83 9
> 2 34,5 21
>
>
> Doing this, I got problems with the NAs in column C.
> I tried to combine the aggregate - function
> aggregate(C, list(B), FUN=(mean, var))
>
> with the following functions
>
> var(C, use="complete.obs")
> median(C, rm.na=TRUE)
>
> but it doesn't work as I want. Has anybody an idea how to do this work?
>
> thank you
> Iksmax
>
> ______________________________________________
> 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.
>

--
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

______________________________________________
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 09 Mar 2008 - 23:33:27 GMT

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 Mon 10 Mar 2008 - 00:30:20 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