From 0c9e4277f37d4ff5c74ca423417d83a69e9b58f4 Mon Sep 17 00:00:00 2001 From: Jose Date: Thu, 27 Oct 2022 11:29:03 -0300 Subject: [PATCH] Iteration intro --- README.org | 4 ++++ script/iteration.R | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100755 script/iteration.R diff --git a/README.org b/README.org index 8b6a45f..be90303 100755 --- a/README.org +++ b/README.org @@ -16,3 +16,7 @@ data using the R programming environment ** Reading data * [[./script/extractpdf.R][Reading pdf files]] + +** Iteration + + * [[./script/iteration.R][Lapply, apply and for loop: brief introduction]] diff --git a/script/iteration.R b/script/iteration.R new file mode 100755 index 0000000..2a555b5 --- /dev/null +++ b/script/iteration.R @@ -0,0 +1,52 @@ +#' --- +#' title: "Iteration in R" +#' date: "2021-12-04" +#' author: "Jose https://ajuda.multifarm.top" +#' output: +#' html_document: +#' code_folding: show +#' toc: yes +#' toc_float: +#' smooth_scroll: true +#' df_print: paged +#' highlight: zenburn +#' --- + +#' remove objects +#' +objects() + +rm(list = ls()) + +#' data + +data(sleep) + +str(sleep) + +#' ## for loop +#' +#' for( var in seq ) expr +#' Where 'var' us a name and 'seq' is a vector and 'expr' an expression + +for(j in names(sleep)) print(class(names(sleep))) + +sapply(sleep, class) + +lapply(sleep, class) + +## The language has other iteration operators (while() and repeat), and +## the usual conditional operators (if ... else). + +#' Check package 'SoDA' + +#' ## References +#' +#' John M. Chambers. Software for Data Analysis: Programming with R. +## @book{chambers2008software, +## title={Software for data analysis: programming with R}, +## author={Chambers, John M}, +## volume={2}, +## year={2008}, +## publisher={Springer} +## }