-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2nd_R_Program_Feb8th'2018.R
83 lines (58 loc) · 1.25 KB
/
2nd_R_Program_Feb8th'2018.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
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
myfirstname<-"Sanjay"
mylastname<-"Pattanayak"
myfirstlast<-c(myfirstname,mylastname)
myfirstlast
rm('myfirstname')
myfirstname
mylastname
myfirstname<-"Jack"
avector<-c(1,2,3,4)
avector
names(avector)<-c("one","two","three","four")
typeof(avector)
elementnames<-names(avector)
elementnames
x<-1:9
x
typeof(x)
is.vector(x)
length(x)
cat<-c("good","bad","good","bad","bad","bad","good")
cat
typeof(cat)
cat2<-factor(cat)
cat2
typeof(cat2)
cat3<-as.integer(cat)
cat4<-as.integer(cat2)
cat3
cat4
cat5<-factor(cat.levels=(c("good","bad"))
)
cat5
days<-c("Monday","Sunday","Tuesday","Wednesday","Thursday","Saturday")
days
days_factor<-factor(days)
days_factor
days_factor<-factor(days,levels = (c("Monday","Sunday","Tuesday","Wednesday","Thursday","Saturday","Friday"))
)
is.factor(days_factor)
x<-1:9
x
is.matrix(x)
mx1<-matrix(x, nrow = 3, ncol = 3, byrow = FALSE)
mx1
is.matrix(mx1)
colnames(mx1)<-c("col1","col2","col3")
rownames(mx1)<-c("row1","row2","row3")
mx1
dimnames(mx1)<-list(c("a","b","c"), c("d","e","f"))
mx1
#matrix multiplication
#mxmul<- mxt1%*%mxt2
#matrix addition
#mtrix transpose
mxt1<-t(mx1)
mxt1
#Inverse of a mtrix
invmx1<-solve(mx1)