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} +## }