this question 및 this one 다음에, 나는 하나의 데이터 세트에서 범주 형 변수를 요약하는 최상의 옵션이 무엇인지 궁금해했습니다.요약 형식의 복수 열
는 I는 제 3 개 변수 범주 (문자 또는 인자) 마지막 숫자 등이다
# A tibble: 10 <U+00D7> 4
empstat_couple nssec7_couple3 nchild07 age_couple
<chr> <fctr> <fctr> <dbl>
1 Neo-Trad Lower Managerial 1child 39
2 Neo-Trad Higher Managerial 1child 31
3 Neo-Trad Manual and Routine 1child 33
4 Trad Higher Managerial 1child 43
으로 데이터 집합을 갖는다. 내가 좋아하는 것이 무엇
이 (출력)
var n p
1: Neo-Trad 6 0.6
2: OtherArrangment 2 0.2
3: Trad 2 0.2
4: Higher Managerial 4 0.4
5: Lower Managerial 5 0.5
6: Manual and Routine 1 0.1
7: 1child 9 0.9
8: 2children 1 0.1
음의 숫자 변수 같은 것입니다, 나는 요약에 의미를 추가하는 방법을 확실입니다.
내가 갈 수있는 가장 기본적인 방법은summarise_each
솔루션이 존재한다면 내가 궁금
library(dplyr)
library(data.table)
a = count(dt, empstat_couple) %>% mutate(p = n/sum(n))
b = count(dt, nssec7_couple3) %>% mutate(p = n/sum(n))
c = count(dt, nchild07) %>% mutate(p = n/sum(n))
rbindlist(list(a,b,c))
것 같아요?
이 내가이
apply(dt, 2, as.data.frame(table)) %>% rbindlist()
가지고 올 수 apply
를 사용
dt %>% summarise_each(funs(count))
작동하지 않습니다하지만 그것은 큰 아니에요.
제안 사항?
데이터
dt = structure(list(empstat_couple = c("Neo-Trad", "Neo-Trad", "Neo-Trad",
"Trad", "OtherArrangment", "Neo-Trad", "Trad", "OtherArrangment",
"Neo-Trad", "Neo-Trad"), nssec7_couple3 = structure(c(2L, 1L,
4L, 1L, 2L, 2L, 1L, 2L, 1L, 2L), .Label = c("Higher Managerial",
"Lower Managerial", "Intermediate", "Manual and Routine"), class = "factor"),
nchild07 = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L,
1L), .Label = c("1child", "2children", ">2children"), class = "factor"),
age_couple = c(39, 31, 33, 43, 32, 28, 28, 40, 33, 26), hldid = 1:10), .Names = c("empstat_couple",
"nssec7_couple3", "nchild07", "age_couple", "hldid"), row.names = c(NA,
-10L), class = "data.frame")
'p'계산과 관련하여 올바른가요? – akrun
@akrun 나는 그렇게 생각한다. 그것은 단순히 비율입니다. – giacomo