Johdanto

Ensimmäisen luento eli tämä verkkosivu, keskittyy perusasioihin. Varmista vielä että käyttämäsi ympäristö on ajan tasalla kännistämällä RStudio ja ajamalla siellä komento library(tidyverse). Tuloksen pitäis olla jotakuinkin sama kuin alla.

> library(tidyverse)
── Attaching packages ─────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
✔ ggplot2 3.1.0     ✔ purrr   0.3.0
✔ tibble  2.0.1     ✔ dplyr   0.7.8
✔ tidyr   0.8.2     ✔ stringr 1.3.1
✔ readr   1.3.1     ✔ forcats 0.3.0
── Conflicts ────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
✖ dplyr::n()      masks .env::n()

Rstudion perusteet

Rstudio on IDE (integrated development environment) eli käyttöliittymä R-kielen käyttöön. R:ää on mahdollista käyttää myös muilla käyttöliittymillä, mutta tällä kurssilla käytämme Rstudiota.

Alla on kaksi videota, jotka suosittelen katsomaan mikäli RStudio ei ole perin pohjin tuttu.

Näiden lisäksi RStudion omilla Webinars-sivulla on täsmävideoita eri aiheista kohdassa RStudio Essentials. Paljolta googlaamiselta säästää myös RStudio iDE:n lunttilappu.

Kotitehtävissä on pari RStudiota koskevaa kysymystä.

R:n perusteet

Tällä kurssilla pääpaino on Tidyverse:n opiskelussa ja R-kielen perusteista yritetään pysytellä erossa mahdollisimman paljon. Samalla on todettava että Tidyversen oppiminen edellyttää hyviä tietoja R:n perusteista.

Mikäli R on sinulle kokonaan vieras, harjoittele perusasioita esimerkiksi käymällä Swirl-paketin 1: R Programming: The basics of programming in R -kurssin. Siis

  1. avaa RStudio
  2. asenna swirl-paketti install.packages("swirl")
  3. lataa paketti library("swirl")
  4. käynnistä swirl ja seuraa ohjeita swirl()

Alkuunpääsy pitäisi näyttää tältä

| Hi! I see that you have some variables saved in your workspace. To keep things running smoothly, I recommend you clean up before starting swirl.

| Type ls() to see a list of the variables in your workspace. Then, type rm(list=ls()) to clear your workspace.

| Type swirl() when you are ready to begin.

Warning message:
package ‘swirl’ was built under R version 3.5.3 
> rm(list=ls())
> swirl()

| Welcome to swirl! Please sign in. If you've been here before, use the same name as you did then. If you are new, call yourself something unique.

What shall I call you? mrks

| Thanks, mrks. Let's cover a couple of quick housekeeping items before we begin our first lesson. First of all, you should know that when you see
| '...', that means you should press Enter when you are done reading and ready to continue.

...  <-- That's your cue to press Enter to continue

| Also, when you see 'ANSWER:', the R prompt (>), or when you are asked to select from a list, that means it's your turn to enter a response, then
| press Enter to continue.

Select 1, 2, or 3 and press Enter 

1: Continue.
2: Proceed.
3: Let's get going!

Selection: 1

| You can exit swirl and return to the R prompt (>) at any time by pressing the Esc key. If you are already at the prompt, type bye() to exit and
| save your progress. When you exit properly, you'll see a short message letting you know you've done so.

| When you are at the R prompt (>):
| -- Typing skip() allows you to skip the current question.
| -- Typing play() lets you experiment with R on your own; swirl will ignore what you do...
| -- UNTIL you type nxt() which will regain swirl's attention.
| -- Typing bye() causes swirl to exit. Your progress will be saved.
| -- Typing main() returns you to swirl's main menu.
| -- Typing info() displays these options again.

| Let's get started!

...

| Please choose a course, or type 0 to exit swirl.

1: R Programming
2: Take me to the swirl course repository!

Selection: 1

| Please choose a lesson, or type 0 to return to course menu.

 1: Basic Building Blocks      2: Workspace and Files        3: Sequences of Numbers       4: Vectors                 
 5: Missing Values             6: Subsetting Vectors         7: Matrices and Data Frames   8: Logic                   
 9: Functions                 10: lapply and sapply         11: vapply and tapply         12: Looking at Data         
13: Simulation                14: Dates and Times           15: Base Graphics             

Selection: 1

  |                                                                                                                                           |   0%

| In this lesson, we will explore some basic building blocks of the R programming language.

...

  |====                                                                                                                                       |   3%
| If at any point you'd like more information on a particular topic related to R, you can type help.start() at the prompt, which will open a menu of
| resources (either within RStudio or your default web browser, depending on your setup). Alternatively, a simple web search often yields the answer
| you're looking for.

...

  |=======                                                                                                                                    |   5%
| In its simplest form, R can be used as an interactive calculator. Type 5 + 7 and press Enter.

> 5 + 7
[1] 12

| You are quite good my friend!

  |===========                                                                                                                                |   8%
| R simply prints the result of 12 by default. However, R is a programming language and often the reason we use a programming language as opposed to
| a calculator is to automate some process or avoid unnecessary repetition.

Datacamp on toinen hyvä paikka R-kielen omatoimiseen opiskeluun ja suosittelen tutustumaan kurssiin Introduction to R. Datacampissa on paljon muita R-kursseja muuan muassa Introduction to the Tidyverse.

Googlelta löydät rajattoman määrän materiaaleja R:n perusteiden opiskeluun:

Teknisten harjoitusten ohella Video: overview and history of R on hyvä johdatus siihen mistä R on tullut ja mitä sen suosion taustalla on.

Kotitehtävissä on paljon R:n perusteita käsittelevää kysymystä. Yritä vastata niihin parhaan kykysi mukaan!

Tidyversen perusteet

Kurssilla paneudutaan erityisesti R-kielen suosittuun murteeseen nimeltä tidyverse. Katso alla oleva Hadley Wickhamin luento johdantona tidyverseen. Kurssin kuluessa pureudutaan kuhunkin luennon teemaan hieman syvemmin, että pääsette alkuun omatoimisessa opiskelussa.

Kotitehtävissä on pari tidyverseä koskeva kysymys


2017-2019 Markus Kainu.

Creative Commons -lisenssi
Tämä teos on lisensoitu Creative Commons Nimeä 4.0 Kansainvälinen -lisenssillä.