Home > front end >  Is there in R stratified function? [closed]
Is there in R stratified function? [closed]

Time:09-24

My question is very simple. This is an assignment from the R course.

a) Install the AER package and load it in R.

b) Load the data set SwissLabor into your workspace and get a first impression of it. Which variables does R consider as factor variables, which ones as numerical ones?

c) Create a baseline table with the variables age, income, education and participation, stratified by foreign and without statistical test for differences. Export the table in a .csv file named “SwissLabor table1.csv”.

I work a long time with R but I don't understand what exactly the author of this exercise wants to see in R code and in output.

I there an error in this assignment? If someone knows how to solve this task, please, help.

Thank!

CodePudding user response:

#a)
install.packages("AER")
library(AER)

#b)
data("SwissLabor")

#c.1) create table one
library(tableone)

table = CreateTableOne(
  data = SwissLabor,
  vars = c("age", "income", "participation", "education" ),
  strata = "foreign",
  test = FALSE
)

table
# Stratified by foreign
# no            yes          
# n                         656           216        
# age (mean (SD))          4.06 (1.09)   3.80 (0.93) 
# income (mean (SD))      10.74 (0.43)  10.54 (0.31) 
# participation = yes (%)   254 (38.7)    147 (68.1) 
# education (mean (SD))   10.04 (2.65)   7.09 (3.05) 

#c.2) save to csv file
table_p = print(table, quote = FALSE, noSpaces = TRUE, printToggle = FALSE)
write.csv(table_p, file = "SwissLabor table1.csv")

  •  Tags:  
  • r
  • Related