How can i select unique observation in group. Reproducible example.
mydata=structure(list(N = c(111L, 111L, 111L, 111L, 112L, 112L, 112L,
111L, 111L, 111L, 111L, 112L, 112L, 112L), group = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), .Label = "control group", class = "factor"),
char = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 2L), .Label = c("bad", "good"), class = "factor")), .Names = c("N",
"group", "char"), class = "data.frame", row.names = c(NA, -14L
))
I need find only unique observation in N by char variable.
So N
contains number of prisoner.
char
contains good or bad behavior
So i must calculate total count of unique numbers of prisoners by good and bad category.
There are two group control and test, i just indicated control.
As we can see unique observations here 111 and 112 number.
Here output which i want
number of unique prisoners for control group
bad 2
good 2
How to perform it?
Edit
mydata=structure(list(N = c(111L, 111L, 111L, 111L, 112L, 112L, 112L,
111L, 111L, 111L, 111L, 112L, 112L, 112L, 111L, 111L, 111L, 111L,
112L, 112L, 112L, 111L, 111L, 111L, 111L, 112L, 112L, 112L),
group = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L), .Label = c("control group", "test group"), class = "factor"),
char = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L,
2L, 2L, 2L), .Label = c("bad", "good"), class = "factor")), .Names = c("N",
"group", "char"), class = "data.frame", row.names = c(NA, -28L
))
output divided by group
control group test group
bad 2 2
good 2 2