---
# System prepended metadata

title: Q&A Session Wednesday 2nd and 3rd November 2022

---

# Q&A Session Wednesday 2nd and 3rd November 2022

We will use this collaborative notebook to annotate questions and answers
First type here your expertise in R

Beginner:ii iiiiiiiiiiiiiiiiiiiiiii
i
i
i
i

i

Now I am much better: ii

I can make my own scripts:ii


### Question 1:
when and why should I integrate a pipe when making a ggplot?

you can pipe ggplot() after you have reshaped your table

### Question 2: using join()
https://angus.readthedocs.io/en/2019/R_Intro_Lesson.html#combining-datasets-using-join

### Question 3: gather and spread
Example: data frame you want to do a heatmap for

| Gene | SA | SB | SC |
| 1    | ---| -- | -- |
| 2    | ---| -- | -- |
| 3    | ---| -- | -- |
| 4    | ---| -- | -- |
| 5    | ---| -- | -- |

pivot.longer(data="xx", names_to="Samples", values_to="Values", cols=-Gene)

| Gene | Samples | Values |
| 1 ----| SA -----| ------ | 
| 1 ----| SB -----| ------ | 
| 1 ----| SC -----| ------ | 
| 2 ----| SA -----| ------ | 
| 2 ----| SB -----| ------ | 
| 2 ----| SC -----| ------ | 
| 3 ----| SA -----| ------ | 
| 3 ----| SB -----| ------ | 
| 3 ----| SC -----| ------ | 
| 4 ----| SA -----| ------ | 
| 4 ----| SB -----| ------ | 
| 4 ----| SC -----| ------ | 
| 5 ----| SA -----| ------ | 
| 5 ----| SB -----| ------ | 
| 5 ----| SC -----| ------ | 

#another example 

n=10
wide <- data.frame(
  ID = c(1:10),
  Time.1 = c(411,723,325,456,579,612,709,513,527,379),
  Time.2 = c(123,300,400,500,600,654,789,906,413,567),
  Time.3 = c(1457,1000,569,896,956,2345,780,599,1023,678)
)

#to reshape wide to a longer format, where each time measurement goes in a column

long <- wide %>% 
  pivot_longer(names_to="Response Time", 
               values_to="Time", 
               cols=-ID)


### Question 4: order of pipes
-Remove the data you dont need first (NAs)
    Use filter 1st
-Do calculations with your dataset 
-Group by and summarize later



### Question 5: when to use c()
We use c() to create a vector, to include several elements in one object
weight_kg -> c(50,40,100,80)
patient_id -> c(234,456,124,155)

