Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Objects:
1. Assign value to object: x = 1, or x <- 1 (case sensitive, meaning x and X are different objects),
2. Object names in R may include numbers or periods, e.g. x.1 <- 20
3. Objects can store character values e.g. xx <- “hello”, R will treat any number as a character if it is stored with
quotation e.g. xx <- “1”, 1 will be treated as character not a number
4. To check what objects are stored in R workspace: LS()c
5. Remove object from workspace: LS()
6. Delete all objects: RM(LS())
Arithmetic Operations
7. E.g x+y will add the values in x and y, similarly all arithmatic operations can be done like:
a. Sqrt(x) to find square root
b. Y^2 to square y
c. Log(y) to find log of y
d. Exp(y) to find antilog or exponent of y
e. Log2(x) to find log base 2 of x
f. Abs(-14) to find absolute value of -14 which will give 14 as output
Things to remember:
8. If you don’t complete the command like typing “print(x” and press enter, then R will give a + sign, the command
will execute once you close the bracket i.e. type “)” and then press enter.
9. Arrow key up will get you the last command, and hitting the arrow key up again will get the previous to the last
command and so on. And arrow down key will get the next command.
10. To comment a code, type # before the code
LESSON 2:
Vector:
Operations on matrix
LESSON 3:
29. read.csv("link of file",header=T,na.strings="?") (CAUTION: use back slash “/” for links)
a. header=t, setting header to true will make the first row of the table as header variables
b. "na.strings" is used to tell R to treat the characters present in the data set as missing values
30. Step 1: setwd("Link of folder“) (CAUTION: use back slash “/” for links)
Step 2: d<-read.csv(“Filename.csv”)
31. Step 1: Library(ISLR)
Step 2: Attach(Auto)
32. To Read.table(file=”/link”,header=true, sep=”\t”)
a. Sep=”\t” tells R in what format the data is..”\t” says the data is tab separated and “,” says data is comma
separated
33. Looking the dataset in spreadsheet: fix(filename)
34. Dimension of the dataset: dim(filename)
35. Omitting the missing values of dataset: Filename=na.omit(filename)
36. Name of the variables: names(filename)
37. Clearing history: rm(list=ls())
38.