Answered step by step
Verified Expert Solution
Link Copied!

Question

00
1 Approved Answer

Using the data frame, chol, for this problem: > load(chol.RData) > head(chol) sex age chol tg ht wt sbp dbp vldl hdl ldl bmi id.2

Using the data frame, chol, for this problem:

> load("chol.RData")

> head(chol)

sex age chol tg ht wt sbp dbp vldl hdl ldl bmi

id.2 M 60 137 50 68.25 111.75 110 70 10 53 74 2.399066

id.3 M 26 154 202 82.75 184.75 88 64 34 31 92 2.698040

id.4 M 33 198 108 64.25 147.00 120 80 22 34 132 3.560993

id.5 F 27 154 47 63.25 129.00 110 76 9 57 88 3.224547

id.6 M 36 212 79 67.50 176.25 130 100 16 37 159 3.868313

id.7 F 31 197 90 64.50 121.00 122 78 18 58 111 2.908479

Write a function, table1, to perform the following task:

Calculate the descriptive statistics for each numeric

variable, including mean, median, standard deviation, the number of non-missing values, and the number of missing values.

The first argument is a data frame.

The second argument is a character vector that contains the names of the variables.

The returned value is a matrix that contains numeric values.

For the values of mean, median, or standard deviation, you can round them to two decimal places in the result.

The expected results look like following:

> table1(chol, c("age"))

Mean Median SD N N_miss

age 22.66 17 15.46 192 0

> table1(chol, c("age", "chol"))

Mean Median SD N N_miss

age 22.66 17 15.46 192 0

chol 198.57 179 66.64 190 2

> table1(chol, c("age", "chol", "tg", "ht", "wt", "bmi"))

Mean Median SD N N_miss

age 22.66 17.00 15.46 192 0

chol 198.57 179.00 66.64 190 2

tg 80.37 68.00 44.63 190 2

ht 61.43 64.00 9.29 192 0

wt 123.55 126.00 49.40 192 0

bmi 3.10 3.07 0.72 192 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Fundamental Accounting Principles

Authors: John Wild, Ken Shaw, Barbara Chiappett

23rd edition

1259536351, 978-1259536359

Students also viewed these Mathematics questions