-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRBasics.R
51 lines (36 loc) · 1.23 KB
/
RBasics.R
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
## Setup the working directory - This is a best practice to do
## In future doing this help you to load data files easily
setwd("~/Research/Gallup/RTutorial/R-Primer/") #this is on a unix enviornment
## you can skip the above if you can't figure out the file path
# R: Absolute basics -- This is how comment looks like in R Just use the hash-tag
## I prefer two hash tags in my code just so easy to identify.
## If you are directly in R console type the below and hit enter
## if you are on R-Studio hit Control + Return ( on a Mac)
"Hi there, We are having Fun with R"
## Creating variables / objects
height <- 4
width <- 6
## you can use "=" but true R programmers use "<-" :)
## you can type height and width to see if the values were assigned correctly.
## Doing calculations
area <- height * width
area
## List the contents of your workspace
ls()
## More arithmatic operations - Since we have already created weight and height lets use them
# Addition
height + width
# Subtraction
height - width
# Division
(height + width) / width
# Exponentiation
height^2
# Modulo
(height^2) %% 4
## Create a new variable
depth <- 8
## remove variable from the workspace
rm(depth)
## if you want to remove all the variables
rm(list = ls(all = TRUE))