I have a dataset like this

```
id <- 1:12
b <- c(0,0,1,2,0,1,1,2,2,0,2,2)
c <- rep(NA,3)
d <- rep(NA,3)

df <-data.frame(id,b)
newdf <- data.frame(c,d)

```

I want to do simple math. If x==1 or x==2 count them and write how many 1 and 2 are there in this dataset. But I don't want to count whole dataset, I want my function count them four by four.

I want to a result like this:

```
> newdf
  one two
1   1   1
2   2   1
3   0   3

```

I tried this with lots of variation but I couldn't success.

```
afonk <- function(x) {
  ifelse(x==1 | x==2, x, newdf <- (x[1]+x[2]))
} 

afonk(newdf$one)

lapply(newdf, afonk)

```

Thanks in advance!

ismail