• Cos’è pigR?
    • Di cosa hai bisogno per leggere (e capire) questo libro.
    • Chi siamo noi (noi, noi)?
    • Se ti piace…
    • Caveat
    • Cookies
    • La foto di copertina.
  • 1 Introduzione
    • 1.1 Cosa c’è da imparare in questo capitolo.
    • 1.2 Convenzioni e guida alla lettura e all’uso del codice.
    • 1.3 Tutti vogliono imparare a usare R.
      • 1.3.1 Provare per credere: App, GUI, IDE e altre diavolerie.
    • 1.4 L’altra faccia della medaglia: troppa fatica.
    • 1.5 R, per pigri.
  • 2 Interfacce e ambienti
    • 2.1 Cosa c’è da imparare in questo capitolo.
    • 2.2 RStudio.
      • 2.2.1 L’interfaccia principale di RStudio.
      • 2.2.2 Il pannello Source.
      • 2.2.3 Il pannello Console.
      • 2.2.4 Il pannello Environment.
      • 2.2.5 Il tab Environment.
      • 2.2.6 Il tab History.
      • 2.2.7 Il pannello Plots.
      • 2.2.8 Il tab Plots.
      • 2.2.9 Il tab Files.
      • 2.2.10 Il tab Packages.
      • 2.2.11 Il tab Help.
    • 2.3 Esercizi.
    • 2.4 Altre risorse.
      • 2.4.1 Risorse in italiano.
      • 2.4.2 Risorse in inglese.
  • 3 Chiedere aiuto
    • 3.1 Cosa c’è da imparare in questo capitolo.
      • 3.1.1 Premessa 1: nessuno legge i manuali (figuriamoci i pigRi)!
      • 3.1.2 Premessa 2: ci sono molti modi di pelare un gatto (e documentarlo).
    • 3.2 L’aiuto di R.
      • 3.2.1 Il tab Help di RStudio.
      • 3.2.2 Funzioni per chiedere aiuto.
    • 3.3 Strategie per cercare aiuto (anche senza parere).
    • 3.4 Esercizi.
    • 3.5 Altre risorse.
      • 3.5.1 Risorse in italiano.
      • 3.5.2 Risorse in inglese.
      • 3.5.3 Niente video?
  • 4 Dati, oggetti, funzioni (e tutto il resto)
    • 4.1 Cosa c’è da imparare in questo capitolo.
      • 4.1.1 Premessa 1: esperimenti e osservazioni.
      • 4.1.2 Premessa 2. Misure e dati, osservazioni e variabili, tabelle.
      • 4.1.3 Anatomia di una tabella.
      • 4.1.4 Un piccolo esercizio.
      • 4.1.5 Tidy vs. untidy (tabelle ordinate e disordinate).
      • 4.1.6 Dati mancanti (missing data).
    • 4.2 R è un linguaggio funzionale che supporta la programmazione orientata a oggetti…
    • 4.3 Il nome delle cose.
    • 4.4 Strutture di dati.
    • 4.5 Vettori atomici.
      • 4.5.1 Vettori ad una dimensione.
      • 4.5.2 Vettori atomici a 2 o più dimensioni: matrici e array.
    • 4.6 I data frame e le liste.
      • 4.6.1 I data frame, nel bene e nel male.
      • 4.6.2 Le liste.
    • 4.7 Altre cose strane: tabelle di conte, serie temporali, date e ore.
    • 4.8 Indirizzare, selezionare.
      • 4.8.1 Indirizzare per posizione.
      • 4.8.2 Usare i nomi.
      • 4.8.3 Usare valori logici.
    • 4.9 attach(), with(), within().
    • 4.10 Funzioni “built-in” e funzioni definite dall’utente.
      • 4.10.1 Semplici funzioni matematiche, trigonometriche, statistiche, logiche, etc.
      • 4.10.2 Operatori.
      • 4.10.3 Funzioni built-in.
      • 4.10.4 Funzioni definite dall’utente.
    • 4.11 Programmare, con stile.
    • 4.12 Un ambiente affollato.
    • 4.13 Altre risorse.
      • 4.13.1 Risorse in italiano.
      • 4.13.2 Risorse in inglese.
  • 5 Dentro e fuori R
    • 5.1 Cosa c’è da imparare in questo capitolo.
    • 5.2 Ogni cosa al suo posto: working directory, progetti, etc.
    • 5.3 Facciamola semplice: il menu Import Dataset.
    • 5.4 Gestire file di testo con readr.
    • 5.5 Tutti i comandi (o quasi) per importare file di testo…
    • 5.6 Altri formati di dati.
      • 5.6.1 Da e per Excel.
      • 5.6.2 Altri formati: foreign e Hmisc e haven.
      • 5.6.3 Un richiamo: file .Rdata e .rds
      • 5.6.4 E’ andato tutto bene?
    • 5.7 Lavorare con i nomi dei file e le directory.
    • 5.8 Appendice 1. Un piccolo dettaglio sulla sintassi.
    • 5.9 Appendice 2. Se sei arrivat* fin qui…
    • 5.10 Altre risorse.
      • 5.10.1 Risorse in inglese.
  • 6 Introduzione alla grafica scientifica con R
    • 6.1 Cosa c’è da imparare in questo capitolo.
    • 6.2 I grafici, fatti bene.
    • 6.3 I sistemi grafici in R.
    • 6.4 Visualizzare o salvare i grafici: i device.
      • 6.4.1 Salvare i grafici: i file come device grafici.
      • 6.4.2 Salvare i grafici di ggplot2 con ggsave.
      • 6.4.3 Le dimensioni del device e le opzioni grafiche.
    • 6.5 R, a colori.
    • 6.6 La grammatica della grafica con ggplot2.
    • 6.7 Grafici per variabili qualitative.
      • 6.7.1 Diagrammi a barre.
      • 6.7.2 Fare di più con i grafici per variabili qualitative.
    • 6.8 Grafici per variabili quantitative.
      • 6.8.1 Istogrammi e altre rappresentazioni della densità.
      • 6.8.2 Boxplot.
      • 6.8.3 Rappresentazioni di indicatori di tendenza centrale e di variabilità.
      • 6.8.4 Grafici a dispersione.
      • 6.8.5 Personalizzare i grafici con ggplot2.
      • 6.8.6 Estensioni per ggplot2.
      • 6.8.7 Veloce veloce: qplot()
    • 6.9 La grafica di base in R: un salvagente?
    • 6.10 Altre risorse.
      • 6.10.1 Risorse in inglese.
  • 7 Esplorare con i numeri
    • 7.1 Cosa c’è da imparare in questo capitolo.
    • 7.2 Una piccola premessa: gruppi, livelli, sottoinsiemi.
    • 7.3 Statistiche riassuntive per dati continui.
      • 7.3.1 Misure di tendenza centrale e di variabilità.
    • 7.4 Altre funzioni utili.
      • 7.4.1 Lavorare sui vettori.
      • 7.4.2 Funzioni che producono statistiche riassuntive.
      • 7.4.3 Statistiche, ordinate.
      • 7.4.4 Statistiche riassuntive per gruppi.
    • 7.5 Ma è normale?
      • 7.5.1 Normal probability plot.
      • 7.5.2 Test statistici per la normalità.
      • 7.5.3 Come fare di meglio con i risultati dei test.
    • 7.6 Intervalli di confidenza.
    • 7.7 Riassumere i dati per le variabili categoriche.
      • 7.7.1 Tabelle di frequenza e contingenza.
      • 7.7.2 Grafici a mosaico.
    • 7.8 Veloce veloce
    • 7.9 Altre risorse.
      • 7.9.1 Risorse in italiano.
      • 7.9.2 Risorse in inglese.
  • 8 Creare report e notebook con R.
    • 8.1 Cosa c’è da imparare in questo capitolo.
    • 8.2 Il minimo indispensabile.
    • 8.3 Gli elementi di un report in R Markdown.
    • 8.4 Altri formati di documento con R Markdown.
    • 8.5 Quarto.
    • 8.6 Altre risorse.
      • 8.6.1 Risorse in italiano.
      • 8.6.2 Risorse in inglese.
  • 9 Lottare con i dati.
    • 9.1 Cosa c’è da imparare in questo capitolo.
    • 9.2 Rendere tidy i dati.
      • 9.2.1 Riordinare con tidyr e dplyr: esempio minimo.
      • 9.2.2 Funzioni avanzate con tidyr.
    • 9.3 il cavallo di battaglia del data wrangling: dplyr.
      • 9.3.1 Estrarre gruppi di righe o colonne.
      • 9.3.2 Riordinare i dati.
      • 9.3.3 Trasformare con mutate().
      • 9.3.4 Riassumere i dati con summarise().
      • 9.3.5 Database e tabelle relazionali: unire tabelle con _join.
    • 9.4 Strutture di controllo.
      • 9.4.1 Loop (o cicli) e cose simili.
      • 9.4.2 Un’alternativa (veloce e ordinata) ai loop: i “functional”.
      • 9.4.3 Esecuzione condizionale.
    • 9.5 La soluzione dell’esercizio.
    • 9.6 Altre risorse.
      • 9.6.1 Risorse in italiano.
      • 9.6.2 Risorse in inglese.
  • 10 Citazioni, crediti, copyright, ringraziamenti.
    • 10.1 Citazioni.
    • Credits e copyright.

pigR: R, per pigri

10 Citazioni, crediti, copyright, ringraziamenti.

v1.0.1 5/11/2023

10.1 Citazioni.

Ecco una lista dei pacchetti usati in questo libro. Sono in ordine alfabetico, e non in ordine di importanza (almeno dal mio punto di vista). Qui ho usato il comando citation() per generare i riferimenti bibliografici che possono essere usati per citare i pacchetti nelle pubblicazioni.

## $base
## To cite R in publications use:
## 
##   R Core Team (2023). _R: A Language and Environment for Statistical
##   Computing_. R Foundation for Statistical Computing, Vienna, Austria.
##   <https://www.R-project.org/>.
## 
## We have invested a lot of time and effort in creating R, please cite it
## when using it for data analysis. See also 'citation("pkgname")' for
## citing R packages.
## 
## $beepr
## To cite package 'beepr' in publications use:
## 
##   Bååth R (2018). _beepr: Easily Play Notification Sounds on any
##   Platform_. R package version 1.3,
##   <https://CRAN.R-project.org/package=beepr>.
## 
## $broom
## To cite package 'broom' in publications use:
## 
##   Robinson D, Hayes A, Couch S (2023). _broom: Convert Statistical
##   Objects into Tidy Tibbles_. R package version 1.0.5,
##   <https://CRAN.R-project.org/package=broom>.
## 
## $car
## To cite the car package in publications use:
## 
##   Fox J, Weisberg S (2019). _An R Companion to Applied Regression_,
##   Third edition. Sage, Thousand Oaks CA.
##   <https://socialsciences.mcmaster.ca/jfox/Books/Companion/>.
## 
## $cowplot
## To cite package 'cowplot' in publications use:
## 
##   Wilke C (2020). _cowplot: Streamlined Plot Theme and Plot Annotations
##   for 'ggplot2'_. R package version 1.1.1,
##   <https://CRAN.R-project.org/package=cowplot>.
## 
## $data.table
## To cite package 'data.table' in publications use:
## 
##   Dowle M, Srinivasan A (2023). _data.table: Extension of
##   `data.frame`_. R package version 1.14.8,
##   <https://CRAN.R-project.org/package=data.table>.
## 
## $dplyr
## To cite package 'dplyr' in publications use:
## 
##   Wickham H, François R, Henry L, Müller K, Vaughan D (2023). _dplyr: A
##   Grammar of Data Manipulation_. R package version 1.1.3,
##   <https://CRAN.R-project.org/package=dplyr>.
## 
## $doBy
## To cite package 'doBy' in publications use:
## 
##   Højsgaard S, Halekoh U (2023). _doBy: Groupwise Statistics, LSmeans,
##   Linear Estimates, Utilities_. R package version 4.6.20,
##   <https://CRAN.R-project.org/package=doBy>.
## 
## ATTENTION: This citation information has been auto-generated from the
## package DESCRIPTION file and may need manual editing, see
## 'help("citation")'.
## 
## $foreign
## To cite package 'foreign' in publications use:
## 
##   R Core Team (2023). _foreign: Read Data Stored by 'Minitab', 'S',
##   'SAS', 'SPSS', 'Stata', 'Systat', 'Weka', 'dBase', ..._. R package
##   version 0.8-85, <https://CRAN.R-project.org/package=foreign>.
## 
## $ggplot2
## To cite ggplot2 in publications, please use
## 
##   H. Wickham. ggplot2: Elegant Graphics for Data Analysis.
##   Springer-Verlag New York, 2016.
## 
## $ggpubr
## To cite package 'ggpubr' in publications use:
## 
##   Kassambara A (2023). _ggpubr: 'ggplot2' Based Publication Ready
##   Plots_. R package version 0.6.0,
##   <https://CRAN.R-project.org/package=ggpubr>.
## 
## $gmodels
## To cite package 'gmodels' in publications use:
## 
##   Warnes GR, Bolker B, Lumley T, SAIC-Frederick RCJCfRCJaC, Program
##   IFbtIR, NIH ot, Institute NC, NO1-CO-12400. CfCRuNC (2022). _gmodels:
##   Various R Programming Tools for Model Fitting_. R package version
##   2.18.1.1, <https://CRAN.R-project.org/package=gmodels>.
## 
## ATTENTION: This citation information has been auto-generated from the
## package DESCRIPTION file and may need manual editing, see
## 'help("citation")'.
## 
## $Hmisc
## To cite package 'Hmisc' in publications use:
## 
##   Harrell Jr F (2023). _Hmisc: Harrell Miscellaneous_. R package
##   version 5.1-1, <https://CRAN.R-project.org/package=Hmisc>.
## 
## $knitr
## To cite package 'knitr' in publications use:
## 
##   Xie Y (2023). _knitr: A General-Purpose Package for Dynamic Report
##   Generation in R_. R package version 1.45, <https://yihui.org/knitr/>.
## 
##   Yihui Xie (2015) Dynamic Documents with R and knitr. 2nd edition.
##   Chapman and Hall/CRC. ISBN 978-1498716963
## 
##   Yihui Xie (2014) knitr: A Comprehensive Tool for Reproducible
##   Research in R. In Victoria Stodden, Friedrich Leisch and Roger D.
##   Peng, editors, Implementing Reproducible Computational Research.
##   Chapman and Hall/CRC. ISBN 978-1466561595
## 
## $kableExtra
## To cite package 'kableExtra' in publications use:
## 
##   Zhu H (2021). _kableExtra: Construct Complex Table with 'kable' and
##   Pipe Syntax_. R package version 1.3.4,
##   <https://CRAN.R-project.org/package=kableExtra>.
## 
## $magrittr
## To cite package 'magrittr' in publications use:
## 
##   Bache S, Wickham H (2022). _magrittr: A Forward-Pipe Operator for R_.
##   R package version 2.0.3,
##   <https://CRAN.R-project.org/package=magrittr>.
## 
## $MASS
## To cite the MASS package in publications use:
## 
##   Venables, W. N. & Ripley, B. D. (2002) Modern Applied Statistics with
##   S. Fourth Edition. Springer, New York. ISBN 0-387-95457-0
## 
## $microbenchmark
## To cite package 'microbenchmark' in publications use:
## 
##   Mersmann O (2023). _microbenchmark: Accurate Timing Functions_. R
##   package version 1.4.10,
##   <https://CRAN.R-project.org/package=microbenchmark>.
## 
## $openxlsx
## To cite package 'openxlsx' in publications use:
## 
##   Schauberger P, Walker A (2023). _openxlsx: Read, Write and Edit xlsx
##   Files_. R package version 4.2.5.2,
##   <https://CRAN.R-project.org/package=openxlsx>.
## 
## $nortest
## To cite package 'nortest' in publications use:
## 
##   Gross J, Ligges U (2015). _nortest: Tests for Normality_. R package
##   version 1.0-4, <https://CRAN.R-project.org/package=nortest>.
## 
## $nycflights13
## To cite package 'nycflights13' in publications use:
## 
##   Wickham H (2021). _nycflights13: Flights that Departed NYC in 2013_.
##   R package version 1.0.2,
##   <https://CRAN.R-project.org/package=nycflights13>.
## 
## $pastecs
## To cite package 'pastecs' in publications use:
## 
##   Grosjean P, Ibanez F (2018). _pastecs: Package for Analysis of
##   Space-Time Ecological Series_. R package version 1.3.21,
##   <https://CRAN.R-project.org/package=pastecs>.
## 
## $plyr
## To cite package 'plyr' in publications use:
## 
##   Hadley Wickham (2011). The Split-Apply-Combine Strategy for Data
##   Analysis. Journal of Statistical Software, 40(1), 1-29. URL
##   https://www.jstatsoft.org/v40/i01/.
## 
## $psych
## To cite package 'psych' in publications use:
## 
##   William Revelle (2023). _psych: Procedures for Psychological,
##   Psychometric, and Personality Research_. Northwestern University,
##   Evanston, Illinois. R package version 2.3.9,
##   <https://CRAN.R-project.org/package=psych>.
## 
## $purrr
## To cite package 'purrr' in publications use:
## 
##   Wickham H, Henry L (2023). _purrr: Functional Programming Tools_. R
##   package version 1.0.2, <https://CRAN.R-project.org/package=purrr>.
## 
## $radiant
## To cite package 'radiant' in publications use:
## 
##   Nijs V (2023). _radiant: Business Analytics using R and Shiny_. R
##   package version 1.6.0, <https://CRAN.R-project.org/package=radiant>.
## 
## $Rcmdr
## To cite the 'Rcmdr' package in publications use:
## 
##   Fox, J., and Bouchet-Valat, M. (2023). Rcmdr: R Commander. R package
##   version 2.9-1.
## 
##   Fox, J. (2017). Using the R Commander: A Point-and-Click Interface or
##   R. Boca Raton FL: Chapman and Hall/CRC Press.
## 
##   Fox, J. (2005). The R Commander: A Basic Statistics Graphical User
##   Interface to R. Journal of Statistical Software, 14(9): 1--42.
## 
## $RColorBrewer
## To cite package 'RColorBrewer' in publications use:
## 
##   Neuwirth E (2022). _RColorBrewer: ColorBrewer Palettes_. R package
##   version 1.1-3, <https://CRAN.R-project.org/package=RColorBrewer>.
## 
## $reshape2
## To cite reshape2 in publications use:
## 
##   Hadley Wickham (2007). Reshaping Data with the reshape Package.
##   Journal of Statistical Software, 21(12), 1-20. URL
##   http://www.jstatsoft.org/v21/i12/.
## 
## $rmarkdown
## To cite package 'rmarkdown' in publications use:
## 
##   Allaire J, Xie Y, Dervieux C, McPherson J, Luraschi J, Ushey K,
##   Atkins A, Wickham H, Cheng J, Chang W, Iannone R (2023). _rmarkdown:
##   Dynamic Documents for R_. R package version 2.25,
##   <https://github.com/rstudio/rmarkdown>.
## 
##   Xie Y, Allaire J, Grolemund G (2018). _R Markdown: The Definitive
##   Guide_. Chapman and Hall/CRC, Boca Raton, Florida. ISBN
##   9781138359338, <https://bookdown.org/yihui/rmarkdown>.
## 
##   Xie Y, Dervieux C, Riederer E (2020). _R Markdown Cookbook_. Chapman
##   and Hall/CRC, Boca Raton, Florida. ISBN 9780367563837,
##   <https://bookdown.org/yihui/rmarkdown-cookbook>.
## 
## $stringr
## To cite package 'stringr' in publications use:
## 
##   Wickham H (2022). _stringr: Simple, Consistent Wrappers for Common
##   String Operations_. R package version 1.5.0,
##   <https://CRAN.R-project.org/package=stringr>.
## 
## $skimr
## To cite package 'skimr' in publications use:
## 
##   Waring E, Quinn M, McNamara A, Arino de la Rubia E, Zhu H, Ellis S
##   (2022). _skimr: Compact and Flexible Summaries of Data_. R package
##   version 2.1.5, <https://CRAN.R-project.org/package=skimr>.
## 
## $tictoc
## To cite package 'tictoc' in publications use:
## 
##   Izrailev S (2023). _tictoc: Functions for Timing R Scripts, as Well
##   as Implementations of "Stack" and "StackList" Structures_. R package
##   version 1.2, <https://CRAN.R-project.org/package=tictoc>.
## 
## ATTENTION: This citation information has been auto-generated from the
## package DESCRIPTION file and may need manual editing, see
## 'help("citation")'.
## 
## $tidyr
## To cite package 'tidyr' in publications use:
## 
##   Wickham H, Vaughan D, Girlich M (2023). _tidyr: Tidy Messy Data_. R
##   package version 1.3.0, <https://CRAN.R-project.org/package=tidyr>.
## 
## $tidyverse
## To cite package 'tidyverse' in publications use:
## 
##   Wickham H, Averick M, Bryan J, Chang W, McGowan LD, François R,
##   Grolemund G, Hayes A, Henry L, Hester J, Kuhn M, Pedersen TL, Miller
##   E, Bache SM, Müller K, Ooms J, Robinson D, Seidel DP, Spinu V,
##   Takahashi K, Vaughan D, Wilke C, Woo K, Yutani H (2019). "Welcome to
##   the tidyverse." _Journal of Open Source Software_, *4*(43), 1686.
##   doi:10.21105/joss.01686 <https://doi.org/10.21105/joss.01686>.
## 
## $vcd
## Meyer D, Zeileis A, Hornik K (2023). _vcd: Visualizing Categorical
## Data_. R package version 1.4-11,
## <https://CRAN.R-project.org/package=vcd>.
## 
## To cite the strucplot framework (e.g., functions mosaic(), sieve(),
## assoc(), strucplot(), structable(), pairs.table(), cotabplot(),
## doubledecker()), additionally use:
## 
##   Meyer D, Zeileis A, Hornik K (2006). "The Strucplot Framework:
##   Visualizing Multi-Way Contingency Tables with vcd." _Journal of
##   Statistical Software_, *17*(3), 1-48. doi:10.18637/jss.v017.i03
##   <https://doi.org/10.18637/jss.v017.i03>.
## 
## If you use the residual-based shadings (in mosaic() or assoc()), please
## cite:
## 
##   Zeileis A, Meyer D, Hornik K (2007). "Residual-based Shadings for
##   Visualizing (Conditional) Independence." _Journal of Computational
##   and Graphical Statistics_, *16*(3), 507-525.
##   doi:10.1198/106186007X237856
##   <https://doi.org/10.1198/106186007X237856>.

Credits e copyright.

la Figura usata per la copertina è di Mark Stebnicki da Pexels Di alcune figure del capitolo 3 non sono riuscito a trovare una fonte precisa, neanche usando la ricerca per immaigni di Google.
La figura 4.2 è stata modificata a partire dalla figura 1 di Szymańska, E., 2018. Modern data science for analytical chemical data - A comprehensive review. Anal Chim Acta 1028, 1–10..
Ho un debito con i reviewer di questo libro: ahnno avuto la pazienza di leggere tutto, cosa che non credo faranno tutt* quell* che, in un modo o nell’altro, lo avranno “fra le mani”.
Gli script usati per generare questo libro sono stati creati da Eugenio Parente (eugenio.parente_at_unibas.it), Università degli Studi della Basilicata, 2021, 2022, 2023 https://github.com/ep142 Gli script sono stati testati (fino ad ottobre 2023) con R 4.0.5, 4.1, 4.2.2, 4.3.0, 4.3.1 (sia build per processori Intel che per arm64) su diversi personal computer Apple (con MacOS 10.14.6, 10.15.7, 13.6). Il codice è disponibile in un repository su GitHub (se proprio siete troppo pigr* per scrivere o fare il copia e incolla).

Le parti di codice sono sotto licenza MIT
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Le parti di testo sono sotto licenza CC BY 4.0