Skip to content

Commit 871903a

Browse files
committed
added R output
1 parent 6a7369b commit 871903a

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
11
*.DS_Store
2+
*.RData
3+
*.Rhistory

img/matlab-figure-4png

-19.8 KB
Binary file not shown.

r.md

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,8 @@ The length of a vector is given by the command ```length```:
174174
175175
myVector <- c(4, 5, 6, 7)
176176
length(myVector)
177+
178+
# > [1] 4
177179
```
178180
A **character** variable can be defined using the symbols ```'``` or ```"```:
179181
```
@@ -194,6 +196,8 @@ The length of a string is given by the command ```char```:
194196
195197
myString <- 'Hello, World!'
196198
nchar(myString)
199+
200+
# > [1] 13
197201
```
198202

199203
A **factor** is a special vector of labelled elements. Usually its elements are discrete and can be either strings or scalars:
@@ -223,10 +227,18 @@ Xmat <- matrix(matElements, 4, 5)
223227
224228
# Number of rows
225229
nrow(Xmat)
230+
231+
# > [1] 4
232+
226233
# Number of columns
227234
ncol(Xmat)
235+
236+
# > [1] 5
237+
228238
# Both
229239
dim(Xmat)
240+
241+
# > [1] 4 5
230242
```
231243
Matrix dimensions can be named, using the commands `dimnames`, `rownames`, or `colnames`.
232244
Names can be assigned also at the definition time:
@@ -243,13 +255,26 @@ colnames(Xmat) <- c(1:5)
243255
244256
# Read the row names and column names
245257
rownames(Xmat)
258+
259+
# > [1] "1" "2" "3" "4"
260+
246261
colnames(Xmat)
247262
263+
# > [1] "1" "2" "3" "4" "5"
264+
248265
# Assign using dimnames
249266
dimnames(Xmat) <- list(c(1:4), c(1:5)) # Notice that in this case we need a list
250267
251268
# Assign at the definition
252-
Xmat <- matrix(sample(20), 4, 5, dimnames = list(c(1:4), c(1:5)) # Same as dimnames command
269+
Xmat <- matrix(sample(20), 4, 5, dimnames = list(c(1:4), c(1:5))) # Same as dimnames command
270+
271+
Xmat
272+
# > Xmat
273+
# 1 2 3 4 5
274+
# 1 6 2 18 15 4
275+
# 2 13 9 8 7 20
276+
# 3 10 14 1 19 5
277+
# 4 11 3 16 12 17
253278
```
254279

255280
An **array** is the matrix extension to more than 2-dimensions. For instance, the following command will assign a 3-dimensional array of dimensions (5 x 6 x 10) to the variable ```myArray```:
@@ -451,4 +476,4 @@ Here, it is possible to find nice examples of data graphs generated using ```ggp
451476
- [R Graphs](http://www.cookbook-r.com/Graphs/)
452477

453478

454-
##[Python tutorial](https://github.com/csmsoftware/Programming-for-data-analysis-tutorial-Matlab-R-Python/blob/master/r.md)
479+
[Python tutorial](https://github.com/csmsoftware/Programming-for-data-analysis-tutorial-Matlab-R-Python/blob/master/r.md)

0 commit comments

Comments
 (0)