Commit 5a89b3d4 authored by Bernd Klaus's avatar Bernd Klaus
Browse files

rewordings and fixes througout the document

parent 237b9ca2
## ----options, include=FALSE----------------------------------------------
library(knitr)
options(digits = 3, width = 80)
opts_chunk$set(echo= TRUE, tidy=FALSE,include = TRUE,
dev= 'png', fig.width = 6, fig.height = 3.5,
opts_chunk$set(echo = TRUE, tidy = FALSE, include = TRUE,
dev = 'png', fig.width = 6, fig.height = 3.5,
comment = ' ', dpi = 300,
cache = TRUE)
......@@ -30,7 +30,7 @@ library("cowplot")
## ----simple_ex_2, echo = TRUE--------------------------------------------
x <- 6
y <- 4
z <- x+y
z <- x + y
z
## ----simple_ex_3, echo = TRUE--------------------------------------------
......@@ -40,7 +40,7 @@ ls()
sqrt(16)
## ----simple_ex_5, echo = TRUE--------------------------------------------
z <- c(5, 9 , 1 ,0)
z <- c(5, 9, 1, 0)
## ----simple_ex_5b, echo = TRUE-------------------------------------------
x <- c(5, 9)
......@@ -48,15 +48,15 @@ y <- c(1, 0)
z <- c(x, y)
## ----simple_ex_6, echo = TRUE--------------------------------------------
seq(1, 9, by=2)
seq(8, 20, length=6)
seq(1, 9, by = 2)
seq(8, 20, length = 6)
## ----simple_ex_7, echo = TRUE--------------------------------------------
x <- seq(1, 10)
## ----simple_ex_8, echo = TRUE--------------------------------------------
rep(1:3,6)
rep(1:3, times = c(6,6,6))
rep(1:3, 6)
rep(1:3, times = c(6, 6, 6))
## ----vec-----------------------------------------------------------------
x <- 1:5
......@@ -66,14 +66,14 @@ x^2
x * y
## ----vec-2---------------------------------------------------------------
x <- c(6,8,9)
x <- c(6, 8 , 9 )
x + 2
## ----calcEx, eval = FALSE------------------------------------------------
## x + cos(pi/y)
## ----summary_1, echo = TRUE--------------------------------------------
x <- c(7.5,8.2,3.1,5.6,8.2,9.3,6.5,7.0,9.3,1.2,14.5,6.2)
x <- c(7.5, 8.2, 3.1, 5.6, 8.2, 9.3, 6.5, 7.0, 9.3, 1.2, 14.5, 6.2)
mean(x)
var(x)
summary(x)
......@@ -85,7 +85,7 @@ summary(x[1:6])
summary(x[7:12])
## ----subscr_2, echo = TRUE---------------------------------------------
x[c(2,4,9)]
x[c(2, 4, 9)]
x[-(1:6)]
head(x)
......@@ -121,18 +121,17 @@ class(a)
str(a)
## ----cbind-ex, echo = TRUE---------------------------------------------
x <- c(5, 7 ,9)
y <- c(6, 3 ,4)
z <- cbind(x,y)
x <- c(5, 7 , 9)
y <- c(6, 3 , 4)
z <- cbind(x, y)
z
dim(z)
## ----matrix_direct, echo = TRUE----------------------------------------
z <- matrix(c(5, 7, 9, 6, 3, 4), nrow = 3)
## ----Matrix-ex, echo = TRUE--------------------------------------------
z <- matrix(c(5, 7 , 9 ,6 ,3 , 4), nrow = 3, byrow = TRUE)
z <- matrix(c(5, 7 , 9 , 6 , 3 , 4), nrow = 3, byrow = TRUE)
z
## ----Matrix-op, echo = TRUE--------------------------------------------
......@@ -142,11 +141,11 @@ y + z
y * z
## ----Matrix-op-4, echo = TRUE------------------------------------------
z[1,1]
z[,2]
z[1:2,]
z[-1,]
z[-c(1,2),]
z[1, 1]
z[, 2]
z[1:2, ]
z[-1, ]
z[-c(1, 2), ]
## ----load-Patients, echo = TRUE----------------------------------------
pat <- read_csv("http://www-huber.embl.de/users/klaus/BasicR/Patients.csv")
......@@ -169,7 +168,8 @@ filter(pat, Height < 1.5, Gender == "f")
filter(pat, (Height < 1.5) | (Gender == "f"))
## ----list_example, echo = TRUE-----------------------------------------
L <- list(one=1, two=c(1,2), five=seq(1, 4, length=5), list(string = "Hello World"))
L <- list(one = 1, two = c(1, 2), five = seq(1, 4, length = 5),
list(string = "Hello World"))
L
## ----list_access, echo = TRUE------------------------------------------
......@@ -194,7 +194,7 @@ bodyfat
head(map_dbl(bodyfat, mean))
## ----function_template, eval=FALSE---------------------------------------
## function_name <- function(argument_1, , argument_2,
## function_name <- function(argument_1, argument_2,
## optional_argument = defautl_value )
## {
## return(...)
......@@ -225,8 +225,8 @@ map_dbl(discard(pat, is_character), mean, na.rm = TRUE)
## ----qplot, eval=FALSE---------------------------------------------------
## qplot(x, y = NULL, ..., data, facets = NULL,
## NA), ylim = c(NA, NA), log = "", main = NULL,
## xlab = deparse(substitute(x)), ylab = deparse(substitute(y)))
## }
## xlab = , ylab = )
##
## ----qplot_example-------------------------------------------------------
bodyfat <- mutate(bodyfat, weight_binned = cut(weight_kg, 5))
......@@ -238,7 +238,8 @@ qplot(abdomen.circum, percent.fat,
## ----qplot_example_facets------------------------------------------------
qplot(abdomen.circum, percent.fat,
color = weight_binned, data = bodyfat, facets = ~weight_binned)
color = weight_binned, data = bodyfat,
facets = ~weight_binned)
## ----embl_logo, results='hide'-------------------------------------------
......@@ -254,33 +255,36 @@ qplot(x, y, data = hex_grid, color = lab, asp = 1) +
title = element_blank())
## ----if-example, echo = TRUE, eval = TRUE------------------------------
w= 3
if( w < 5 ){
d=2
}else{
d=10
## ----if_example, echo = TRUE, eval = TRUE------------------------------
w = 3
if (w < 5) {
d = 2
} else {
d = 10
}
d
## ----for-example, echo = TRUE, eval = TRUE-----------------------------
## ----for_example, echo = TRUE, eval = TRUE-----------------------------
h <- seq(from = 1, to = 8)
s <- integer() # create empty integer vector
for(i in 2:10)
s <- numeric() # create empty vector
for (i in 1:8)
{
s[i] <- h[i] * 10
}
s
## ----maps_for------------------------------------------------------------
map_dbl(h, ~.x*10)
## ----ifelse-example, echo = TRUE, eval = TRUE--------------------------
s <- seq(from = 1, to = 10)
binary.s <- ifelse(s > 5, "high", "low")
binary.s
binary_s <- ifelse(s > 5, "high", "low")
binary_s
## ----sol-1, echo = TRUE, results='hide'--------------------------------
rep(6,6)
rep(c(5,8),4)
c(rep(5,4), rep(8,4))
rep(6, 6)
rep(c(5, 8), 4)
c(rep(5, 4), rep(8, 4))
## ----calcExerc, results='hide'-------------------------------------------
x + cos(pi/y)
......@@ -302,15 +306,17 @@ summary(Shop2)
## alternative: turn into a tibble and use map functions
y_mat <- t(matrix(y, nrow = 3, ncol = 5, byrow = FALSE))
y_tibble <-as_tibble(y_mat)
y_tibble <- as_tibble(y_mat)
names(y_tibble) <- c("Shop_1", "Shop_2", "Shop_3")
map(y_tibble, summary)
## ----apply-test, echo = TRUE, results = 'hide'-------------------------
## ----apply-test, echo = TRUE, results = 'hide', message=FALSE----------
pat <- read_csv("http://www-huber.embl.de/users/klaus/BasicR/Patients.csv")
pat
pat$Weight[2] <- mean(pat$Weight, na.rm=TRUE)
map_dbl(keep(pat, is_double), mean)
pat$Weight[2] <- mean(pat$Weight, na.rm = TRUE)
pat
pat <- mutate(pat, BMI = Weight / Height^2)
......@@ -328,7 +334,7 @@ qplot(x, y, data = hex_grid, color = lab, asp = 1) +
title = element_blank())
## ----sol_embl_logo, results='hide'---------------------------------------
## ----sol_embl_logo, results='hide', fig.keep='none'----------------------
load("hex_grid.Rdata")
embl_colors <- c("#E2001A", "#6FAA46")
......@@ -343,6 +349,30 @@ qplot(x, y, data = hex_grid, color = lab, asp = 1) +
scale_colour_manual(values = embl_colors )
## ----sol_read, echo = TRUE, results = 'hide'---------------------------
source("http://www-huber.embl.de/users/klaus/BasicR/readError.R")
test <- readError(1000)
## number of errors
sum(test == "error")
## error probability
sum(test == "error") / 1000
prop.table(table(test))
readError2 <- function(noBases){
positions <- integer(noBases) ## initialize vector
for (i in 1:noBases ) {
positions[i] <- rbinom(n = 1, size = 1, prob = 0.05)
}
return(ifelse(positions, "correct", "error"))
}
### equivalent function
rbinom(n = 1000, size = 1, prob = 0.05)
## ----seesionInfo, results='markup'---------------------------------------
sessionInfo()
......
This diff is collapsed.
This diff is collapsed.
File deleted
File added
# add space after comma
(,)([^\s]) \1 \2
# replace library calls
library\(("[\S]+")\) \1,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment