First sight of R

Oke, this is began when Rob Hyndman the Forecasting Professor asked me to get acquaintance with R. Who is R? me? Obviously no.. it is a statistical package, free and of course legally installed. You can download it in (thanks to Mr.Gum-Gum for giving me the site). If you are in Indonesia, please directly to go to this link to download it.

Hmm.. in the homepage, there is a sophisticating graph, makes everyone want to download it. But I really not suggest this to non-GUI person, because you’ll hate it. It’s based on console, similar with MATLAB console without the fancy buttons or drop-down menus. Another similarity is both of them are good at working in vector or matrix, I mean that you should not know the differences between float, long or double in primitive data types as in Java Programming.
You only really need to know when to use the integer or float or the string one. Does it make you better? :))

First lesson from this early usage is function c. I just wondered why it must one character to name a function, rrrggh.. just type help(c) in your console, and surprisingly it will open a html view through your browser, wow MATLAB couldn’t do this! maybe it can but not implemented yet.

C is an abbreviation from Combine Values, into a Vector or List. As far as I concern, a vector is just one dimension whether it is column or row, but let us see.. How about List? physically List is same with array.

If I want to make vector (1 4 5), what should I type?
> c(1,4,5)
*it is doesn’t matter when you should put your ; at the last or not, doesn’t make any differences*

Wait what is the variable name of the vector I just made? it has no name. How to put it in a specific name? Type this..
> varname <- c(1,4,5)
*it named ‘varname’, of course you can rename it by yourself. Did you see ‘<-‘ it replaced the ‘=’ or assignment syntax. Little bit funny ya.. :p But, from this marker I got that the idea was same with Java or C or MATLAB which is the assignment should be done from right to the left.

How to combine integer with float in one vector? That’s easy, although it may violate the concept of data type integrity, but with R you freely do anything 😉
> c(2,6,7.8)
*look at the result, the integer one will adapt the pattern, you may try with two or more digits precision and observe what the result

I think that’s not difficult to combine with the character, let’s try
> c(2,6,”f”)
*do you see what happened? yap! all the values will turn into character

This next features is same with MATLAB, that fill in the vector with sequential number. As a example, I want to create new vector named ‘seq’=[1 2 3 4 5 6 7 8 9 10].
If you try this code below, so you may a diligent learner but not the smart one 😀
> seq <- c(1,2,3,4,5,6,7,8,9,10)
Please try this one, because it will optimize your performance a lot, especially typing performance 😀
> seq <- c(1:10)
If you see the ‘:’, it means ‘until’, similar with MATLAB’s

Surely, you can combine the sequential number with a character or float or other integer. Just try to make this vector (“1” “2” “3” “4” “5” “6” “3” “5.6” “t”)
> v <- c(1:6, 3, 5.6, “t”)

These explanations above only about vector, about list I am going to type it tomorrow 😉 Please do not quote anything from this blog because it is just my first sight.. See u!

2 thoughts on “First sight of R

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s