…about R, for beginners

[This article was first published on Tales of R » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

These days I was remembering my beginnings as a linux user few years ago, and how I found R (possibly in a very unlikely way: searching for a SPSS alternative in Linux). For two years, R had been almost impossible for me. I didn’t understand its syntax (I don’t have programming background), and luckily I had installed R Commander (Rcmdr) to perform simple analysis and plots…

Another feature of Rcmdr (that I didn’t use) was that every click to a button remains in a part of Rcmdr’s console, and then it can be copied, used and modified. Indeed, the ‘copypaste‘ thing has revealed to me as the best way to acquire, recyle, modify and run commands.

Have you installed R? You can try this (nice) code:

# First we store an object called ‘object’ in R’s memory (just like a big calculator)

object <- seq(1,100,  by=5)

# ‘Object’ stores the sequence (seq) from 1 to 100, by 5. That is: 1,  6, 11, 16, 21 26, 31… If you type ?seq in the console, you will have a brief help.

# With R, you can calculate big numbers, logarythms and fractions storing its components, with less chance of errors than with an ordinary calculator.

# You can create new variables from old ones:

logobject <- log10(object)

# ‘Logobject’ stores the decimal logarythm of every value inside ‘object’. That is:


# You can also plot the variables with simple functions like plot:


plot(object, logobject)

plot(object, logobject, col = "red", xlab="My X axis", ylab= "This is my Y axis", main="My first plot")

# As you can see, is not very difficult to change the color “argument”, from “red” to “green” or “blue” for instance. The title, instance of “My first R plot” can be changed to “My coloured R plot”, or the labels of the axes. Don’t forget to store these commands and new ones, in a plain Text document, Wordpad etc.. so you can recycle them and fix syntax errors!

# If you feel confident, you can try this. The spoiler is here, by DWin

dat <- data.frame(t=seq(0, 2*pi, by=0.1) )

xhrt <- function(t) 16*sin(t)^3

yhrt <- function(t) 13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t)

dat$y = yhrt(dat$t)

dat$x = xhrt(dat$t)

with(dat, plot(x,y, type="l"))

with(dat, polygon(x,y, col="hotpink"))

To leave a comment for the author, please follow the link and comment on their blog: Tales of R » R.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)