Reputation: 159
Is there any way I can export this data to a csv file, instead of typing things in manually.
Below is the output from Hmisc
describe
function:
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
--------------------------------------------------------------------------------------------------------------------------------------------------------------------
Dataset:
> 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
Upvotes: 0
Views: 862
Reputation: 263451
Probably not going to be easy. You could use capture.output
but then you would need to parse the sections differently depending on their class and counts. You could also assign the results to a data object and try to work with that, but again, there will be a diversity of formats:
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"
Upvotes: 0
Reputation: 389225
I doubt writing it to csv would be helpful. Try writing it to text file instead.
cat(capture.output(Hmisc::describe(data)), file = 'result.txt', sep = '\n')
Upvotes: 1