Google Developers R Programming Video Lectures

[This article was first published on One Tip Per Day, 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.

I got this Google Developers R Programming Video Lectures from Stephen’s blog – Getting Genetics Done.

Very useful R tutorial for beginner! Short and efficient. 
Here is what I learned after watching the lectures:

stop() and warning() function
I was asked this question during a job interview. stop(‘message’) will print out the error message and stop the function. warning(‘message’) will print out the error message but continue the function.

To return index of an array/dataframe, use which(df, arr.ind=T), e.g. which(is.na(df), arr.ind=T) will return the column/row index of NA elements.

Passing additional arguments using an ellipsis(…), for example:
myFunc <- function(a, ...){
   return colMean(a, …);
}
will allow us to call the function like myFun(a, na.rm=T), for example. 
You can also record the ellipsis arguments by
args=list(…)

return() vs. invisible()
return() will return the values and print out in the screen.
invisible will return the values but not print out to the screen.

use recall() to call recursive function in R. For example, instead of writing recursive function like
myFunc <- function(a)
{
return(if(a>1, myFunc(log(a)), a));
}

, write it as
myFunc <- function(a)
{
return(if(a>1, recall(log(a)), a));
}

To leave a comment for the author, please follow the link and comment on their blog: One Tip Per Day.

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)