Summary: control output format for summary(dataFrame) calls.
Given data frame dataFrame, summary(dataFrame) creates an output which is easy to read only when the number of columns in dataFrame is small.
Question:
How to produce an output that contains 1 fact at a time?
For example:
dataFrame <- data.frame(x=rnorm(100), y=rnorm(100), z=rnorm(100));
summary(dataFrame);
gives:
x y z
Min. :-2.13427 Min. :-2.12077 Min. :-2.4453
1st Qu.:-0.53324 1st Qu.:-0.78915 1st Qu.:-0.4100
Median : 0.05675 Median :-0.22321 Median : 0.1356
Mean : 0.09102 Mean :-0.04939 Mean : 0.1306
3rd Qu.: 0.69685 3rd Qu.: 0.58358 3rd Qu.: 0.7847
Max. : 2.48204 Max. : 2.65971 Max. : 2.0504
and the desired output would be:
x
Min. :-2.13427
1st Qu.:-0.53324
Median : 0.05675
Mean : 0.09102
3rd Qu.: 0.69685
Max. : 2.48204
y
Min. :-2.13427
1st Qu.:-0.53324
Median : 0.05675
Mean : 0.09102
3rd Qu.: 0.69685
Max. : 2.48204
z
Min. :-2.13427
1st Qu.:-0.53324
Median : 0.05675
Mean : 0.09102
3rd Qu.: 0.69685
Max. : 2.48204
To get the summary of a data frame in R, use the summary() function. To create a data frame in R, use data. frame() function.
Descriptive statistics in R (Method 1): summary statistic is computed using summary() function in R. summary() function is automatically applied to each column. The format of the result depends on the data type of the column. If the column is a numeric variable, mean, median, min, max and quartiles are returned.
The easiest way to create summary tables in R is to use the describe() and describeBy() functions from the psych library.
You can use function lapply()
to apply function summary()
to each column and then cbind()
to show data as column.
lapply(dataFrame,function(x) cbind(summary(x)))
$x
[,1]
Min. -2.09200
1st Qu. -0.56240
Median 0.07069
Mean -0.04267
3rd Qu. 0.54060
Max. 2.07800
$y
[,1]
Min. -2.55200
1st Qu. -0.62190
Median -0.07336
Mean -0.06966
3rd Qu. 0.58540
Max. 2.07100
$z
[,1]
Min. -2.80800
1st Qu. -0.52890
Median -0.03279
Mean -0.06263
3rd Qu. 0.53730
Max. 2.88500
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With