first commit

This commit is contained in:
AG Damsbo 2022-09-19 13:04:09 +02:00
parent 4e974ee6f3
commit 5a8a1a43f6
2 changed files with 63 additions and 0 deletions

13
advancedR.Rproj Normal file
View File

@ -0,0 +1,13 @@
Version: 1.0
RestoreWorkspace: Default
SaveWorkspace: Default
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX

50
notes.R Normal file
View File

@ -0,0 +1,50 @@
##
##
library(advr38pkg)
system.time(rnorm(1e6))
select()
### Debugging
my_fun <- function(a, b) {
# browser()
la <- my_log(a)
lb <- my_log(b)
la + lb
}
debugonce(my_fun) # This is nice!!
my_fun(1,0)
###
### Exercise on coercing
(mat <- matrix(sample(c(TRUE, FALSE), 12, replace = TRUE), 3))
matrix(as.numeric(mat),nrow=nrow(mat))
mat + 0
###
advr38pkg::sum_every(1:10, 2)
# debugonce(advr38pkg::sum_every)
# 3.3.3.2
col_mean <- function(x,n){
mean(x[[n]],na.rm=TRUE)
}
colMeans(iris[sapply(iris,is.numeric)])
# 3.3.3.3
mat <- matrix(0, 10, 2); mat[c(5, 8, 9, 12, 15, 16, 17, 19)] <- 1; mat
(decode <- matrix(c(0, NA, 1, 2), 2))
decode
decode[mat+1]
skim(mat)