Important R snippets

After the huuuggeee amount of homeworks that I had to do lately, I found myself repeatedly googling for these snippets a lot. So I will start a series of posts on snippets that are important for me. Yes, for me, because the main reason I do this is to make my own one-stop-snippets-center when I’m doing my long queue of homeworks that I reaalllyy hope will end soon.

# Clear workspace environment
rm(list=ls())

# Create scatterplot and save to file
pdf('lgPower-Yr.pdf')
plot(lgPower ~ Yr)
dev.off()

# Several plots in one graph
par(mfrow=c(2,2))

# Concatenate string
paste('h=',i)

# Select vector index by value
y <- which(x>0.05)

# Get unique elements in a vector
unique(x)

# Get/set current working directory
getwd()
setwd(dir)

# Make a function
function.name <- function(x,y){}

Good resources for your R coding needs:

These snippets and resource list will be updated from time to time as long as I still need to use R ;p

Advertisement

About Audi Primadhanty

Audi Primadhanty
This entry was posted in 'the other side' and tagged , , . Bookmark the permalink.

One Response to Important R snippets

  1. Pingback: Important LaTex snippets | audi primadhanty

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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