]> git.donarmstrong.com Git - don.git/blob - r/learning_r/variables_and_objects.mdwn
add more information on variables
[don.git] / r / learning_r / variables_and_objects.mdwn
1 [[!meta title="Learning R: Basic Variables and Objects"]]
2
3 Variables and Objects
4 ---------------------
5
6 Like most computer languages, R uses variables as a means of storing
7 information in memory and retrieving it later. Variables can be
8 assigned to using the `<-` or `=` operator. For example, to assign the
9 number `5` to the variable `foo`, you would write
10
11 [[!sweavealike echo=1 results="hide" code="""
12 foo <- 5
13 """]]
14
15 Variables can retrieved simply by referring to them by name. For
16 example, to add `8` to the variable `foo` and store the result in
17 `bar`, you would do the following:
18
19 [[!sweavealike echo=1 results="hide" code="""
20 bar <- foo + 8
21 """]]
22
23
24 In R, variables are more correctly called objects, because they have
25 structure and do not directly refer to a specific memory location.
26
27 Basic Types
28 ----------
29
30 Vectors
31 =======
32
33 A vector is the major data type used in R. You can think of it as a
34 line of cells, each containing a value of the same type.
35 [Type here means a number or a string.]
36
37
38 Lists
39 =====
40
41
42 Object Attributes
43 -----------------
44
45
46
47