-3

I have some example data.frame:

x<- data.frame(c(0,1,2,1,2,1,2),c(0,1,2,1,2,2,1),c(0,1,2,1,2,1,2),c(0,1,2,1,2,2,1))
colnames(x) <- c('PV','LA','Wiz','LAg')

I want to count occurrence by hole row. The result should look like:

PV LA Wiz Lag Replace
0  0  0   0   1
1  1  1   1   2
2  2  2   2   2
1  2  1   2   1
2  1  2   1   1

The row 0 0 0 0 was replaced 1, row 1 1 1 1 was replaced 2 times etc.

Do you have any idea, how can I do it ?

Blazej
  • 19
  • 3
  • I have no idea how you derive the result from the input. – Roland Mar 14 '14 at 11:08
  • Please make your example clearer. What is `Replace`? Which column do you want to use to count occurrence? – Mikko Mar 14 '14 at 11:14
  • Is `ID` supposed to become `Replace`? – maloneypatr Mar 14 '14 at 11:19
  • All of columns, the algorithm have to check replace of hole row, as you can see. The row 0 0 0 0 was replaced 1, row 1 1 1 1 was replaced 2 times etc. Is my example more clearer? I thought that ID column may help in counting replace. – Blazej Mar 14 '14 at 11:40
  • 1
    I am still struggling to understand what you want to do. – Mikko Mar 14 '14 at 11:49
  • Please inform yourself on how to ask a [good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducable example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – Jaap Mar 14 '14 at 11:54

1 Answers1

1

Maybe you want this?

as.data.frame(table(do.call(paste, x[,-1])))
#     Var1 Freq
#1 0 0 0 0    1
#2 1 1 1 1    2
#3 1 2 1 2    1
#4 2 1 2 1    1
#5 2 2 2 2    2
Roland
  • 127,288
  • 10
  • 191
  • 288