[R] Count
Sarah Goslee
sarah.goslee at gmail.com
Wed May 13 16:27:38 CEST 2015
Hi,
On Wed, May 13, 2015 at 5:58 AM, venkadesan venky <venkynov10 at gmail.com> wrote:
> Hello Team,
>
> I have data like this
>
> have Small doubts on the following calculation
>
>
> For example,
>
> Employee size Camp 1 camp 2 Camp 3
>
> 1 1 0 0
>
> 2 0 0 1
>
> 3 1 1 0
>
> 1 0 0 1
>
> 2 1 0 0
Using dput() is easier for everyone else than just pasting your data in.
> for employee size columns values are repeated and its not uniqe id so i
> want to find that how many zero's are there in 1st id and 2nd id?
>
> for example for employee size(1st row) 1=0+0
>
> (4th row) 1=0+0
>
> here totally 4 zero,s i want results like this
I'm not at all sure I understand what you're asking, but what about:
testdata <- data.frame(EmpSize = c(1,2,3,1,2), Camp1 = c(1,0,1,0,1),
Camp2 = c(0,0,1,0,0), Camp3 = c(0,1,0,1,0))
aggregate(rowSums(testdata[, -1] == 0), list(testdata$EmpSize), FUN="sum")
--
Sarah Goslee
http://www.functionaldiversity.org
More information about the R-help
mailing list