-
Notifications
You must be signed in to change notification settings - Fork 26
/
Notebook for chapter 1.Rmd
109 lines (98 loc) · 1.99 KB
/
Notebook for chapter 1.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
title: "R Notebook"
output: html_notebook
---
This is an [R Markdown](http://rmarkdown.rstudio.com) Notebook. When you execute code within the notebook, the results appear beneath the code.
Try executing this chunk by clicking the *Run* button within the chunk or by placing your cursor inside it and pressing *Ctrl+Shift+Enter*.
```{r}
plot(cars)
```
Basic commands on R
Assigning variable
```{r}
x<- 2*8
x
```
Numeric Vector and operation on it
```{r}
y <- c(2.3, 1, 5)
y
```
```{r}
length(y)
mode(y)
class(y)
```
sequence of integers storing in vector
```{r}
mynums <- 10:1
mynums
```
operating on Numeric vector
```{r}
sum(mynums)
min(mynums)
max(mynums)
range(mynums)
```
standard deviation, mean and median
```{r}
mean(mynums)
sd(mynums)
median(mynums)
```
Indexing Numeric vector
```{r}
mynums[2]
mynums[1:4]
mynums[-4] # retrieve everything except fourth position
```
character vectors
```{r}
gender <- c('F', 'M', 'M', 'F', 'F')
gender
class(gender)
```
Finding repitition of a character
```{r}
gender[gender == 'F']
```
operating on Data frames
```{r}
participant <- c('louis', 'paula', 'vincenzo')
mydf <- data.frame(participant, score = c(67, 85, 32))
mydf
mydf$score
mean(mydf$score)
```
Indexing on Data frame
```{r}
mydf[1,] # first row
mydf[, 1][2]
```
Indexing
```{r}
mydf[2, ] # 2nd column
```
PLOTING
```{r}
mean(mydf$score)
str(mydf)
summary(mydf)
```
Loading files
```{r}
covid_19 <- read.csv('india_covid_19_statewise_status.csv')
covid_19
```
ASSIGNMENT
Assignment for chapter -1
1. Create a Numeric vector with 10 elements ranging between 20 to 30, name it Mynums. Find maximum and minimum element of the vector. Compute Sum operation on the vector put it in a variable z. Find out the 4,5,6 th element of the vector.
2. Create a 10 element numeric vector and compute mean, median and Standard deviation of the vector.
3. Create a dataframe with 5 participants and their math score. Calculate mean of their score.
Student name Math score
Louis 67
Paul 86
Vincenzo 80
Tim 56
Dorothy 91