Iteration intro
This commit is contained in:
parent
46246663fd
commit
0c9e4277f3
|
@ -16,3 +16,7 @@ data using the R programming environment
|
||||||
** Reading data
|
** Reading data
|
||||||
|
|
||||||
* [[./script/extractpdf.R][Reading pdf files]]
|
* [[./script/extractpdf.R][Reading pdf files]]
|
||||||
|
|
||||||
|
** Iteration
|
||||||
|
|
||||||
|
* [[./script/iteration.R][Lapply, apply and for loop: brief introduction]]
|
||||||
|
|
|
@ -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}
|
||||||
|
## }
|
Loading…
Reference in New Issue