-
Notifications
You must be signed in to change notification settings - Fork 1
/
lab_2.Rmd
66 lines (55 loc) · 1 KB
/
lab_2.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
---
title: "lab_2"
author: Sahir Khan
date: August 4, 2024
output: pdf_document
---
```{r}
vec <- c(1,2,3,4)
class(vec)
char_vec <- c(1,2,3,"4")
print(char_vec)
class(char_vec)
```
```{r}
#matrix declaration
data <- c(1,2,3,4,5,6)
m <- matrix(data)
print(m)
m <- matrix(data=data,nrow=3,ncol=2)
print(m)
# By row filling
m <- matrix(data=data,nrow=3,ncol=2, byrow=T)
print(m)
# Matrix Access
print(m[1,2])
print(m[1,])
print(m[,2])
# Incrementing matrix by constant
new_matrix <- m+5
print(new_matrix)
```
```{r}
# List all variables
ls()
# remove variable
rm(char_vec)
ls()
```
```{r}
# Sequence command - to print elements in certain order, seq(start,end,step)
seq(1,100)
seq(1,10,0.5)
# Repeat command - to repeat a specific command n times
rep(seq(1,10), times=3)
```
```{r}
# Set random seed generator to runif(iterations,start,end)
set.seed(1)
runif(10,100,200)
# Round - rounding number, round(operation, place)
set.seed(2)
round(runif(10,100,200),2)
# Integer entries only
as.integer(runif(10,100,200))
```