我需要將2行和2列變量從crosstab()(Package:descr)生成的高維頻率表從R導出到excel而不改變圖案/格式。具體來說,我想在excel中輸出相同的輸出,因爲在R控制檯上顯示使用crosstab()生成的高維表。在此先感謝...如何將表/交叉表從r保存爲excel,同時保持格式爲
install.packages("descr")
library(descr)
ID <- seq(1:177)
Age <- sample(c("0-15", "16-29", "30-44", "45-64", "65+"), 177, replace = TRUE)
Sex <- sample(c("Male", "Female"), 177, replace = TRUE)
Country <- sample(c("England", "Wales", "Scotland", "N. Ireland"), 177, replace = TRUE)
Health <- sample(c("Poor", "Average", "Good"), 177, replace = TRUE)
Survey <- data.frame(Age, Sex, Country, Health)
head(Survey)
crosstab_1 <- crosstab(Survey, row.vars = c("Age", "Sex"), col.vars = c("Health", "Country"),
type = "f", addmargins = FALSE)
print(crosstab_1)
我需要導出到Excel以交叉表格式,因爲它是在控制檯中出來,通過打印(crosstab_1)功能。
代碼如下: – Biswa