Created
April 17, 2012 14:31
-
-
Save geofferyzh/2406352 to your computer and use it in GitHub Desktop.
RinAction - R Functions - Statistical 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
################################################# | |
## Basic Stats Functions ## | |
################################################# | |
# quantile(x,probs) -- Quantiles where x is the numeric vector where | |
# quantiles are desired | |
# -- y <- quantile(x, c(0.3, 0.84)) | |
# range(x) -- Range | |
# -- range(c(1,2,3,4)) returns c(1,4) | |
# -- diff(range(c(1,2,3,4))) returns 3 | |
# sum(x) -- sum(c(1,2,3,4)) returns 10 | |
# diff(x,lag=n) -- lagged difference | |
# min(x) | |
# max(x) | |
# scale(x,center=TRUE, scale=TrUE) | |
#################### | |
# Standardizing Data | |
#################### | |
# 1 - standardize to 0 mean and 1 sd | |
newdata <- scale(mydata) | |
# 2 - standardize to arbitrary mean and sd | |
newdata <- scale(mydta)*SD + M | |
# 3 - standardize a column/variable | |
newdata <- transform(mydata, myvar = scale(myvar)*10+50) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment