I have a dataframe on which I want to do a descriptive analysis and present it in a document.
For this, I use the librarysummarytools
The code is as follows (in Rmarkdown):
library(readxl)
datos_def <- read_excel("datos_def_excel")
datos_modelo <- subset(datos_def, select = c("SAP", "sexo", "edad"))
datos_modelo$SAP <- factor(datos_modelo$SAP,labels = c("Buena salud","Mala salud"))
datos_modelo$sexo <- factor(datos_modelo$sexo,labels = c("Mujer","Hombre"))
library(summarytools)
view(dfSummary(datos_modelo)) # genera la tabla en formato html
and the generated table is as follows:
Basically I want all the words that are in English to be converted to Spanish. I understand that if it can be done, it should be changed manually word by word. I explain:
For example:
In the Stats/Values column of the age variable I want to change the word "Mean" to "Media"
Change the column title "Graph" to "Graphic"
"Distinc values" for "Distinct values"
"[Numeric]" to "[Numeric]"
Column headings don't bother me as much as I can pass the generated file from html to docx and change it from within Word. But since I have many more variables than those that appear in this question, it would be much more feasible to be able to change them from Rstudio, especially I am interested in changing the words in the Stats/Values columns.
Translations in summarytools
In the documentation of the package 12.2 Define and Use Custom Translations (it is in English) you can use the function ...
... to customize the language. Within this function you have to add the complete path where the respective template is located in csv , download it and edit the column
custom
. The implementation would look like this:Result
The footer can be disabled, so it won't appear in the screenshot above.
Employee Data
You can reproduce the above with
'datos_de_csv.csv'
:If you want to know what is the path configured on your computer (computer) for
R
you can usegetwd()