有没有什么方法可以将这些数据导出到csv文件,而不是手动键入内容。以下是Hmisc describe函数的输出:
library(Hmisc) # Hmisc describe
> Hmisc::describe(data)
data
3 Variables 6 Observations
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
ID
n missing distinct Info Mean Gmd
6 0 3 0.857 112.2 1.267
Value 110 112 113
Frequency 1 2 3
Proportion 0.167 0.333 0.500
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Date
n missing distinct
6 0 3
Value 23/04/2018 24/04/2018 25/04/2018
Frequency 3 2 1
Proportion 0.500 0.333 0.167
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Revenue
n missing distinct Info Mean Gmd
6 0 6 1 74 17.2
lowest : 51 65 70 85 86, highest: 65 70 85 86 87
Value 51 65 70 85 86 87
Frequency 1 1 1 1 1 1
Proportion 0.167 0.167 0.167 0.167 0.167 0.167
--------------------------------------------------------------------------------------------------------------------------------------------------------------------数据集:
> data
ID Date Revenue
1 113 23/04/2018 51
2 113 23/04/2018 87
3 113 23/04/2018 70
4 112 24/04/2018 85
5 112 24/04/2018 65
6 110 25/04/2018 86发布于 2021-05-20 09:40:53
我怀疑将其写入csv是否有帮助。请尝试将其写入文本文件。
cat(capture.output(Hmisc::describe(data)), file = 'result.txt', sep = '\n')发布于 2021-05-20 09:49:44
这可能并不容易。您可以使用capture.output,但是您需要根据它们的类和计数对这些部分进行不同的解析。您也可以将结果分配给一个数据对象,然后尝试使用该数据对象,但同样,也会有多种格式:
obj <- describe(iris)
str(obj)
# this is the canonical example of a dataframe but it doesn't even capture all the cases.
List of 5
$ Sepal.Length:List of 6
..$ descript: chr "Sepal.Length"
..$ units : NULL
..$ format : NULL
..$ counts : Named chr [1:13] "150" "0" "35" "0.998" ...
.. ..- attr(*, "names")= chr [1:13] "n" "missing" "distinct" "Info" ...
..$ values :List of 2
.. ..$ value : num [1:35] 4.3 4.4 4.5 4.6 4.7 4.8 4.9 5 5.1 5.2 ...
.. ..$ frequency: num [1:35(1d)] 1 3 1 4 2 5 6 10 9 4 ...
..$ extremes: Named num [1:10] 4.3 4.4 4.5 4.6 4.7 7.3 7.4 7.6 7.7 7.9
.. ..- attr(*, "names")= chr [1:10] "L1" "L2" "L3" "L4" ...
..- attr(*, "class")= chr "describe"
$ Sepal.Width :List of 6
..$ descript: chr "Sepal.Width"
..$ units : NULL
..$ format : NULL
..$ counts : Named chr [1:13] "150" "0" "23" "0.992" ...
.. ..- attr(*, "names")= chr [1:13] "n" "missing" "distinct" "Info" ...
..$ values :List of 2
.. ..$ value : num [1:23] 2 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 3 ...
.. ..$ frequency: num [1:23(1d)] 1 3 4 3 8 5 9 14 10 26 ...
..$ extremes: Named num [1:10] 2 2.2 2.3 2.4 2.5 3.9 4 4.1 4.2 4.4
.. ..- attr(*, "names")= chr [1:10] "L1" "L2" "L3" "L4" ...
..- attr(*, "class")= chr "describe"
$ Petal.Length:List of 6
..$ descript: chr "Petal.Length"
..$ units : NULL
..$ format : NULL
..$ counts : Named chr [1:13] "150" "0" "43" "0.998" ...
.. ..- attr(*, "names")= chr [1:13] "n" "missing" "distinct" "Info" ...
..$ values :List of 2
.. ..$ value : num [1:43] 1 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.9 3 ...
.. ..$ frequency: num [1:43(1d)] 1 1 2 7 13 13 7 4 2 1 ...
..$ extremes: Named num [1:10] 1 1.1 1.2 1.3 1.4 6.3 6.4 6.6 6.7 6.9
.. ..- attr(*, "names")= chr [1:10] "L1" "L2" "L3" "L4" ...
..- attr(*, "class")= chr "describe"
$ Petal.Width :List of 6
..$ descript: chr "Petal.Width"
..$ units : NULL
..$ format : NULL
..$ counts : Named chr [1:13] "150" "0" "22" "0.99" ...
.. ..- attr(*, "names")= chr [1:13] "n" "missing" "distinct" "Info" ...
..$ values :List of 2
.. ..$ value : num [1:22] 0.1 0.2 0.3 0.4 0.5 0.6 1 1.1 1.2 1.3 ...
.. ..$ frequency: num [1:22(1d)] 5 29 7 7 1 1 7 3 5 13 ...
..$ extremes: Named num [1:10] 0.1 0.2 0.3 0.4 0.5 2.1 2.2 2.3 2.4 2.5
.. ..- attr(*, "names")= chr [1:10] "L1" "L2" "L3" "L4" ...
..- attr(*, "class")= chr "describe"
$ Species :List of 5
..$ descript: chr "Species"
..$ units : NULL
..$ format : NULL
..$ counts : Named num [1:3] 150 0 3
.. ..- attr(*, "names")= chr [1:3] "n" "missing" "distinct"
..$ values :List of 2
.. ..$ value : chr [1:3] "setosa" "versicolor" "virginica"
.. ..$ frequency: num [1:3(1d)] 50 50 50
..- attr(*, "class")= chr "describe"
- attr(*, "descript")= chr "iris"
- attr(*, "dimensions")= int [1:2] 150 5
- attr(*, "class")= chr "describe"https://stackoverflow.com/questions/67612749
复制相似问题