Reputation: 1029
I'm new to R and am trying to create custom values in the 'Stats / Values' column in R. I use the dfSummary function as follows:
dfSummary(as.data.frame(y), headings = FALSE, varnumbers = FALSE, labels.col = TRUE, max.distinct.values = 25))}
Example output I get in the 'Stats / Values' column is 1. Male, 2. Female.
How can I customise this column? I have a list called index and text. e.g. index = [0,1], text = ['Male','Female']. Based on this data I would like the 'Stats / Values' column to be 0. Male, 1. Female.
A second example: index = [0,1,9], text = ['Car','Truck', 'Plane']. 'Stats / Values' column should be 0. Car, 1. Truck, 9. Plane.
What is a simple way to do this?
Upvotes: 1
Views: 170
Reputation: 6911
You could change the levels of the string variable beforehand:
d <- data.frame(index = c(0,1,9), text = c('Car','Truck', 'Plane'))
d$text = with(d, sprintf('%s..%s', index, text))
dfSummary(d)
output (cropped):
-----------------------------------------------------
No Variable Stats / Values Freqs (% o
---- ------------- ----------------------- ----------
2 text 1. 0..Car 1 (33.3%)
[character] 2. 1..Truck 1 (33.3%)
3. 9..Plane 1 (33.3%)
-----------------------------------------------------
However, I couldn't find an option to turn off the enumeration of levels, but see yourself: ?st_options
Upvotes: 2