£15001 - 20000 £25001 - 30000£35001 - 40000£35001 - 40000£35001 - 40000£25001 - 30000
我有一个表,看起来像这样:
性别strong>时间strong>Payband strong>你可以做
pay <- c("£15,001-20000", "£20001-25000", "£25001-30000", "£35001-40000")
with(subset(df, Time == 'full time'), t(table(Gender, factor(Payband, pay)))) |>
as.data.frame() |>
tidyr::pivot_wider(names_from = 'Gender', values_from = 'Freq') |>
dplyr::rename(Payband = Var1)
#> # A tibble: 4 x 3
#> Payband female male
#> <fct> <int> <int>
#> 1 £15,001-20000 0 0
#> 2 £20001-25000 0 0
#> 3 £25001-30000 1 1
#> 4 £35001-40000 1 0
with(subset(df, Time == 'part time'), t(table(Gender, factor(Payband, pay)))) |>
as.data.frame() |>
tidyr::pivot_wider(names_from = 'Gender', values_from = 'Freq') |>
dplyr::rename(Payband = Var1)
#> # A tibble: 4 x 3
#> Payband female male
#> <fct> <int> <int>
#> 1 £15,001-20000 0 1
#> 2 £20001-25000 0 0
#> 3 £25001-30000 0 0
#> 4 £35001-40000 1 1