-
Notifications
You must be signed in to change notification settings - Fork 0
/
Chapter 24.Rmd
58 lines (42 loc) · 967 Bytes
/
Chapter 24.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
title: "Chapter 24"
author: "Julin Maloof"
date: "2023-09-13"
output: html_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
library(bench)
library(tidyverse)
```
## 24.3.1 Exercises
### 1. What are faster alternatives to lm()? Which are specifically designed to work with larger datasets?
lsfit
lm.fit
fastlm
.lm.fit
speedlm
### 2. What package implements a version of match() that’s faster for repeated lookups? How much faster is it?
fastmatch
### 4. rolling mean
rollmean from zoo
### 5. optim alternatives
optimParallel
```{r}
x1 <- rnorm(10000)
w1 <- runif(10000)
x2 <- rnorm(10000000)
w2 <- runif(10000000)
cp1 <- function(x,w) crossprod(x,w)[[1]]
cp2 <- function(x,w) sum(x*w)
r1 <- mark(crossprod10K=cp1(x1,w1),
sum10K=cp2(x1,w1)) %>%
mutate(expression=names(expression))
r2 <-mark(
crossprod10M=cp1(x2,w2),
sum10M=cp2(x2,w2)) %>%
mutate(expression=names(expression))
bind_rows(r1,r2)
```