Browse Source

Tidyverse

master
Pjotr Prins 8 months ago
parent
commit
e5a0a646e7
4 changed files with 86 additions and 2 deletions
  1. +1
    -1
      README.md
  2. +0
    -1
      doc/rstudio-tips.md
  3. +52
    -0
      doc/test.Rmd
  4. +33
    -0
      doc/using-tidyverse.Rmd

+ 1
- 1
README.md View File

@@ -9,7 +9,7 @@ Install RStudio with R.

With GNU Guix install

guix package -i r r-markdown r-rmarkdown
guix package -i r r-markdown r-rmarkdown r-tidyverse r-hash

# Data



+ 0
- 1
doc/rstudio-tips.md View File

@@ -2,7 +2,6 @@

## Useful keyboard shortcuts


In markdown mode:

Ctrl-Alt-I Insert code block


+ 52
- 0
doc/test.Rmd View File

@@ -28,3 +28,55 @@ plot(pressure)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

## Environments


R environments are used to bind names against values. In
this case the subjectid is the name.

```{r}
id <- new.env()
id$16K0021 = 'first'
```

oops, can't start with a number

```{r}
id$m16K0021 = 'first'
ls(id, all.names = TRUE)
```

Note that data frames use environment too with the $ notation.

To add material to an environment we create a new environment (a hash of hash). So

```{r}
mydata <- new.env()
mydata$days = 21
mydata$name = "Pjotr Prins"
id$m16K0021 = mydata
ls(id$m16K0021, all.names = TRUE)
id$m16K0021$name
```

That works well. Step is to be able to parametrize

```{r}
id[["m16K0021"]]$days
```

So you can see the dollar notation is just syntactic sugar.

```{r}
id[["m16Ktest"]] = new.env()
test = id[["m16Ktest"]]
test$name = "Jan Wolkers"
test$days = 22
ls(id, all.names = TRUE)
ls(test, all.names=TRUE)
test$name
```


See also http://adv-r.had.co.nz/Environments.html

+ 33
- 0
doc/using-tidyverse.Rmd View File

@@ -0,0 +1,33 @@
---
title: "using_tidyverse"
author: "Pjotr"
date: "03/03/2020"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## R Tidyverse

The new way of analysing R data is the tidyverse https://www.tidyverse.org/ which includes the online book 'R for Data Science'.

Instead of dataframes we use Tibbles now. First import the data - make sure FACTORS is off and tables and columns show.

```{r}
plot(ind_attr$ELISA ~ ind_attr$Time_to_diagnosis)
```

we want to turn ind_attr into a tibble with

```{r}
tb = as_tibble(ind_attr)
tb
```

```{r}
ggplot(data = tb) + geom_point(mapping = aes(y=ELISA, x = Time_to_diagnosis))
```



Loading…
Cancel
Save