Friday, November 8, 2013

R–Variables

Using variables in R isn’t as hard as it might appear to be.

Let’s see an example.

> c <- 3
> print(c)
[1] 3
>



So in the example above we use a variable named “c” and assign it a value of 3. We also use print command to print the value stored in the variable.

> b <- "Hi"
> b
[1] "Hi"
> print(b)
[1] "Hi"
>



In this example we assign a string value to the variable.


Now let’s see a case when we try to assign multiple values to a variable.

> g <- (6:80)
> g
[1] 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
[27] 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
[53] 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
>



 


 


Technorati Tags: ,,,,,,,,,,,,,,

Windows Live Tags: Variables,example,size,Consolas,Courier,Monospace,margin,width,csharpcode,ffffff,kwrd,preproc,html,attr,lnum


WordPress Tags: Variables,example,size,Consolas,Courier,Monospace,margin,width,csharpcode,ffffff,kwrd,preproc,html,attr,lnum


Blogger Labels: Variables,example,size,Consolas,Courier,Monospace,margin,width,csharpcode,ffffff,kwrd,preproc,html,attr,lnum

No comments:

Post a Comment