-
Notifications
You must be signed in to change notification settings - Fork 2
/
R
executable file
·154 lines (154 loc) · 3.55 KB
/
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
-COMBINED command to make Data
data<-c(1:10)
-entering numerical items as data
data<-c(1:10)
-entering numerical items as data
data<-c(1:10)
-entering text items as data
> day<-c('monday','tuesday')
> day
[1] "monday" "tuesday"
> day1<-c(day,"friday")
> day1
[1] "monday" "tuesday" "friday"
-using scan to make numerical data
> data=scan()
1: 1 2 3 4 6 887 23 423
9:
Read 8 items
> data
[1] 1 2 3 4 6 887 23 423
-get working directory
getwd()
-r treats columns as seperate samples or variables and rows represents replicates or observations
> y<-matrix(1:20,nrow=5,ncol=4)
> y
[,1] [,2] [,3] [,4]
[1,] 1 6 11 16
[2,] 2 7 12 17
[3,] 3 8 13 18
[4,] 4 9 14 19
[5,] 5 10 15 20
> y<-matrix(nrow=5,ncol=4)
> y
[,1] [,2] [,3] [,4]
[1,] NA NA NA NA
[2,] NA NA NA NA
[3,] NA NA NA NA
[4,] NA NA NA NA
[5,] NA NA NA NA
> y<-matrix(nrow=5,ncol=3)
> y
[,1] [,2] [,3]
[1,] NA NA NA
[2,] NA NA NA
[3,] NA NA NA
[4,] NA NA NA
[5,] NA NA NA
> y<-matrix(1:15,nrow=5,ncol=3)
> y
[,1] [,2] [,3]
[1,] 1 6 11
[2,] 2 7 12
[3,] 3 8 13
[4,] 4 9 14
[5,] 5 10 15
> y<-matrix(1,15,234,23123,123,45,7889,213,76,21,67,23,65,42,432,nrow=5,ncol=3)Error in matrix(1, 15, 234, 23123, 123, 45, 7889, 213, 76, 21, 67, 23, :
unused arguments (23123, 123, 45, 7889, 213, 76, 21, 67, 23, 65, 42, 432)
> y<-matrix(1:15,nrow=5,ncol=3)
> y
[,1] [,2] [,3]
[1,] 1 6 11
[2,] 2 7 12
[3,] 3 8 13
[4,] 4 9 14
[5,] 5 10 15
> y=scan()
1:
> y
[,1] [,2] [,3]
[1,] 1 6 11
[2,] 2 7 12
[3,] 3 8 13
[4,] 4 9 14
[5,] 5 10 15
> d<
+
> d<-c(1,2,3,4)
> e<-c("red","white","red",
+
> e<-c("red","white","red",NA)
> e
[1] "red" "white" "red" NA
> f<-c(TRUE,TRUE,TRUE,FALSE)
> mydata<-data.frame(d,e,f)
> mydata
d e f
1 1 red TRUE
2 2 white TRUE
3 3 red TRUE
4 4 <NA> FALSE
> names(mydata)<-c("ID","Color","Passed")
> mydata
ID Color Passed
1 1 red TRUE
2 2 white TRUE
3 3 red TRUE
4 4 <NA> FALSE
> row.names(mydata)<-c("one","two","three","four")
> mydata
ID Color Passed
one 1 red TRUE
two 2 white TRUE
three 3 red TRUE
four 4 <NA> FALSE
> mydata(one,Color)
Error: could not find function "mydata"
> mydata[one][Color]
Error in `[.data.frame`(mydata, one) : object 'one' not found
> mydata["\one"]["Color"]
Error: '\o' is an unrecognized escape in character string starting ""\o"
> mydata["one"]["Color"]
Error in `[.data.frame`(mydata, "one") : undefined columns selected
> mydata[one][Color]
Error in `[.data.frame`(mydata, one) : object 'one' not found
> ls()
[1] "d" "data" "day" "day1" "e" "f" "mydata" "x"
[9] "x1" "y" "z1" "z2"
> mydata[3:5]
Error in `[.data.frame`(mydata, 3:5) : undefined columns selected
> myframe[1:3]
Error: object 'myframe' not found
> mydata[1:3]
ID Color Passed
one 1 red TRUE
two 2 white TRUE
three 3 red TRUE
four 4 <NA> FALSE
> mydata[c("one","Color")]
Error in `[.data.frame`(mydata, c("one", "Color")) :
undefined columns selected
> mydata[c("ID","Color")]
ID Color
one 1 red
two 2 white
three 3 red
four 4 <NA>
> mydata[2:3]
Color Passed
one red TRUE
two white TRUE
three red TRUE
four <NA> FALSE
> mydata[3:3]
Passed
one TRUE
two TRUE
three TRUE
four FALSE
> mydata[1:3]
ID Color Passed
one 1 red TRUE
two 2 white TRUE
three 3 red TRUE
four 4 <NA> FALSE