You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Elements of a matrix can be referenced by specifying the index along each dimension (e.g. "row" and "column") in single square brackets.
356
+
Elements of a matrix can be referenced by specifying the index along each
357
+
dimension (e.g. "row" and "column") in single square brackets.
319
358
320
359
```{r}
321
360
mdat[2, 3]
@@ -398,22 +437,25 @@ names(xlist)
398
437
> {: .solution}
399
438
{: .challenge}
400
439
401
-
Lists can be extremely useful inside functions. Because the functions in R are able to return only a single object, you can "staple" together lots
402
-
of different kinds of results into a single object that a function can return.
440
+
Lists can be extremely useful inside functions. Because the functions in R are
441
+
able to return only a single object, you can "staple" together lots of different
442
+
kinds of results into a single object that a function can return.
403
443
404
444
A list does not print to the console like a vector. Instead, each element of the
405
445
list starts on a new line.
406
446
407
447
Elements are indexed by double brackets. Single brackets will still return
408
-
a(nother) list. If the elements of a list are named, they can be referenced by the `$` notation (i.e. `xlist$data`).
448
+
a(nother) list. If the elements of a list are named, they can be referenced by
449
+
the `$` notation (i.e. `xlist$data`).
409
450
410
451
411
452
### Data Frame
412
453
413
454
A data frame is a very important data type in R. It's pretty much the *de facto*
414
455
data structure for most tabular data and what we use for statistics.
415
456
416
-
A data frame is a *special type of list* where every element of the list has same length (i.e. data frame is a "rectangular" list).
457
+
A data frame is a *special type of list* where every element of the list has same
458
+
length (i.e. data frame is a "rectangular" list).
417
459
418
460
Data frames can have additional attributes such as `rownames()`, which can be
419
461
useful for annotating data, like `subject_id` or `sample_id`. But most of the
@@ -455,27 +497,33 @@ is.list(dat)
455
497
class(dat)
456
498
```
457
499
458
-
Because data frames are rectangular, elements of data frame can be referenced by specifying the row and the column index in single square brackets (similar to matrix).
500
+
Because data frames are rectangular, elements of data frame can be referenced by specifying
501
+
the row and the column index in single square brackets (similar to matrix).
459
502
460
503
```{r}
461
504
dat[1, 3]
462
505
```
463
506
464
-
As data frames are also lists, it is possible to refer to columns (which are elements of such list) using the list notation, i.e. either double square brackets or a `$`.
507
+
As data frames are also lists, it is possible to refer to columns (which are elements of
508
+
such list) using the list notation, i.e. either double square brackets or a `$`.
465
509
466
510
```{r}
467
511
dat[["y"]]
468
512
dat$y
469
513
```
470
514
471
-
The following table summarizes the one-dimensional and two-dimensional data structures in R in relation to diversity of data types they can contain.
515
+
The following table summarizes the one-dimensional and two-dimensional data structures in
516
+
R in relation to diversity of data types they can contain.
472
517
473
518
| Dimensions | Homogenous | Heterogeneous |
474
519
| ------- | ---- | ---- |
475
520
| 1-D | atomic vector | list |
476
521
| 2-D | matrix | data frame |
477
522
478
-
> Lists can contain elements that are themselves muti-dimensional (e.g. a lists can contain data frames or another type of objects). Lists can also contain elements of any length, therefore list do not necessarily have to be "rectangular". However in order for the list to qualify as a data frame, the lenghth of each element has to be the same.
523
+
> Lists can contain elements that are themselves muti-dimensional (e.g. a lists can contain
524
+
> data frames or another type of objects). Lists can also contain elements of any length,
525
+
> therefore list do not necessarily have to be "rectangular". However in order for the list
526
+
> to qualify as a data frame, the lenghth of each element has to be the same.
0 commit comments