« New R User Group in Houston | Main | R co-creator Ross Ihaka wins Lifetime Achievement Award in Open Source »

November 09, 2010

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a010534b1db25970b013488d671e5970c

Listed below are links to weblogs that reference Promote your favorite R functions:

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

Several handy functions are listed here: http://stackoverflow.com/questions/1295955/what-is-the-most-useful-r-trick

it's not a function, but the '%in%' operator is great, such as:


%in%:

books <- books[books$genre %in% c('Romance', 'Fantasy', 'Science Fiction'),]

... saves multiple == & == & == etc. for referencing columns

all of the file. and dir. commands:


file.create()... dir.create... etc.:

... good for file management and automating various processes.


system():

... good for calling other applications like perl, or another R instance, or anything you can do from a command line.


those are the ones that I can think of off hand.

oh... and,

.Platform

...is great too for cross-platform development. Haven't tested this yet, but... yeah, that's the idea

I think learning about functions that can be used to debug R code have been the biggest boon to my productivity.

dput(): for getting the code to generate an object
str(): compactly print the structure of any object
methods(), getS3method(), and getAnywhere(): to find the code for a generic function
debug(), undebug(), traceback(), and browser(): for function debugging

transform, within

David, I think your last line should read:

sum(n.obj)

I count 28 rather than 27:

as.character(subset(as.data.frame(installed.packages()),!is.na(Priority))$Package)

gets you the list above ...

I'll put in votes for sweep, scale, subset, match, merge, cumsum/cumprod ...

example() - I wish that was the second function I learned, right after help().

is there a way to see the previous "functions of the day"?

Matt, there's not right now, but it's a great suggestion! I'll see if we can implement that feature for a future update to inside-R.org.

ave() is not well known, but can be very useful

My own functions are my favorite. :)
here's one I especially find useful

getfirsts <- function(data, searchcol){

# Receives a data frame and a search column in that data frame.
# Returns a data frame of the first occurances of all unique values of of the
# "search" column.

rows <- as.data.frame(match(unique(data[[searchcol]]), data[[searchcol]]))
firsts = data[rows[[1]],]

return(firsts)
}

The comments to this entry are closed.


R for the Enterprise

Got comments or suggestions for the blog editor?
Email David Smith.
Follow revodavid on Twitter Follow David on Twitter: @revodavid

Search Revolutions Blog