Iteration intro

This commit is contained in:
Jose 2022-10-27 11:29:03 -03:00
parent 46246663fd
commit 0c9e4277f3
2 changed files with 56 additions and 0 deletions

View File

@ -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]]

52
script/iteration.R Executable file
View File

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