[R] working with unequal rows

Michael Dewey lists at dewey.myzen.co.uk
Sun Apr 10 14:56:42 CEST 2016


Dear Saba

I think the aggregate function is what you need

?aggregate

should help you on the next step

On 10/04/2016 12:26, Saba Sehrish via R-help wrote:
> Hi
> I have a data frame with rows specifying companies (codes are assigned to companies) and columns specify months (monthly data). The data is based on male (M) and female (F) information for each month. Following is an example of how my data looks like:
>
>
>      01   02   03   04
> 001   M   M   M   na
> 001   F   M   M   M
> 002   M   na   F   F
> 003   F   F   F   M
> 003   F   F   M   na
> 003   M   M   M   M
>
>
> na= no male/female.
> Now, I want to firstly add rows with similar codes to see total number of Male and Female in each month for each company. Secondly, I need to calculate fraction of Female in each month (F/ M+F) for each one of these companies. For example, in first month of company 001, there is a male and a female working, so in this month the fraction of female is 0.5. I need to know the coding to get this fraction for my whole data.
>
> Kindly guide me in this regard.
>
> Thanks
> Saba
>
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> 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.
>

-- 
Michael
http://www.dewey.myzen.co.uk/home.html



More information about the R-help mailing list