Created
April 17, 2012 14:44
-
-
Save geofferyzh/2406427 to your computer and use it in GitHub Desktop.
RinAction - R Functions - Useful Functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################################### | |
## Other Useful Functions ## | |
########################################### | |
# remove a self-written function from memory | |
rm('knn') | |
# length of object | |
x <- length(c(2,5,6,7)) | |
x | |
# generate a sequence | |
indices <- seq(1,10,2) | |
indices | |
# Repeat | |
y <- rep(1:3, 2) | |
y | |
# Divide continuous variabl x into factor with n levels | |
# Create pretty breakpoints | |
# Divide a continous variable x into n intervals, by selecting | |
# n+1 equality spaced rounded value. Often used in plotting | |
#concatenate the objects and outputs them to the screen or a file | |
firstname <- c("Jane") | |
cat("Hello", firstname, "\n") | |
# Random sampling using sample() function | |
set.seed(1) # use the same seed to regenerate same permutation | |
x <- 1:100 | |
sample(x) # random permutation | |
sample(x,50) # select 50 random sample | |
sample(x,50,replace=TRUE) # sampling with replacement |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment