I have a data frame in R that looks like the following. Actually my real df data frame is much bigger than here, but I really don't want to confuse anyone, so I try to simplify things as much as possible.
So there is a data frame.
id <-c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3)
a <-c(3,1,3,3,1,3,3,3,3,1,3,2,1,2,1,3,3,2,1,1,1,3,1,3,3,3,2,1,1,3)
b <-c(3,2,1,1,1,1,1,1,1,1,1,2,1,3,2,1,1,1,2,1,3,1,2,2,1,3,3,2,3,2)
c <-c(1,3,2,3,2,1,2,3,3,2,2,3,1,2,3,3,3,1,1,2,3,3,1,2,2,3,2,2,3,2)
d <-c(3,3,3,1,3,2,2,1,2,3,2,2,2,1,3,1,2,2,3,2,3,2,3,2,1,1,1,1,1,2)
e <-c(2,3,1,2,1,2,3,3,1,1,2,1,1,3,3,2,1,1,3,3,2,2,3,3,3,2,3,2,1,3)
df <-data.frame(id,a,b,c,d,e)
df
Basically I would like to get the occurrences of numbers for each column (a, b, c, d, e) and for each group id (1,2,3) (for this last grouping see my column id).
So, for column a and for id number 1 (for the last see the column identifier), the code will be something like this:
as.numeric(table(df[1:10,2]))
[1] 3 7
: a ( , 1 ), , "1" 3 , "3" 7 .
, . a id id 2 ( . ):
as.numeric(table(df[11:20,2]))
[1] 4 3 3
: a , 2 id), , "1" 4 , "2" 3 "3" 3 .
. ( ). , , , df , ...
, , df dataframe , :
for (z in (2:ncol(df))) assign(paste("df",z,sep="."),df[,z])
, df.2 df $a, df.3 df $b, df.4 df $c .. Im , , ...
, "" ?