Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Basics: TH TH TH TH TH TH TH

Download as pdf or txt
Download as pdf or txt
You are on page 1of 3

BASICS

install.packages("package")
library(package)
?function
ARITHMETIC FUNCTIONS
+, -, *, /
x**2, x^2
abs(x)
sqrt(x)
round(x,digits=n)
log(x)
log10(x)
exp(x)
IMPORTING/EXPORTING DATA
getwd()
setwd("path")
read.table(file="path/dat.ext"),header=TRUE)
read.csv(file="path/dat.ext"),header=TRUE)
write.csv(dat,file="path/datname.csv")
write.table(dat,file="path/datname.txt")
GETTING STARTED WITH DATA
head(dataframe)
tail(dataframe)
str(dataframe)
summary(dataframe)
attach(dataframe)
data.frame(var1,var2,)
subset(dataframe)
sort(x,decreasing=FALSE)
order()
length(x)
dim(x)
WORKING WITH OBJECTS
<c(,)
seq(from=,to=,by=)
a:b
rep(x,n)
cbind(,) rbind(,)
x[i]
x[i:j]
x[i,j]
x[i,]
x[,j]
x$var1
newvar<-factor(oldvar,levels=,labels=)
levels(var)
LOGICAL OPERATIONS
<,>
<=, >=
==
!=
&
|

install R package
load an installed package
open help file for a function
plus, minus, multiply, divide
x squared
absolute value of x
square root of x
round x to n digits
natural logarithm of x (base e)
common logarithm of x (base 10)
e raised to the power of x
identify current working directory
set the location of the working directory
read in a text file
read in a csv file
write a csv file
write a text file
produces first 6 observations
produces last 6 observations
structure of data set
provides numeric summary of data set
attach data set to call variables by name
create a data frame object
create a subset data frame
sort the values of x in increasing order
can be used to sort a data frame by values of a variable
length of an object
dimension of a matrix (number of rows and columns)
object assignment
combine values into a vector or list
create a sequence of numbers
the sequence of integers from a to b
repeat the item x n times
combine objects by columns or rows
the ith element of the vector x
the ith through jth elements of the vector x
the element in the ith row and jth column of x
the entire ith row of x (all columns)
the entire jth column of x (all rows)
the entire variable named var1 in the data frame x
make a numeric variable a factor variable
levels of a factor variable
less than, greater than
less than or equal to, greater than or equal to
equal
not equal
and
or

SPECIAL OPERATIONS
if (condition) dothis else dothis
ifelse(test,yes,no)
my.f<-function(arg1,arg2){statements}
return(x)
for (i in 1:n){ statements}
OBJECT TYPES
is.numeric(x)
is.character(x)
is.logical(x)
is.vector(x)
is.list(x)
is.data.frame(x)
is.matrix(x)
is.factor(x)
is.NA(x)
is.factor(x)
as.factor(x)
SUMMARY STATISCS
favstats(var~group)
sum(x)
mean(x)
median(x)
sd(x)
range(x)
min(x)
max(x)
summary(x)
quantile(x=,probs=)
tapply(var,group,function)
tapply(var,list(group1,group2),function)
NA
mean(x,na.rm=TRUE)
table(x)
table(x)/length(x)
table(var1,var2)
addmargins(my.tab)
prop.table(my.tab,margin=1)
FIGURES
plot(x,y)
points(x,y)
abline()
matplot(x,y)
pie(table(x))
barplot(table(x))
stem(x)
boxplot(x)
boxplot(x~group)
boxplot(x~group1+group2)
boxplot(var1,var2)
hist(x)
qqnorm(x)
qqline(x)
legend(position,names)
pairs(~ x1 + x2,data=mydata)
colors()
par()

if/else statements
evaluates test as T/F and returns yes/no
create a function
return object from a function
loop over index i
logical evaluation returning TRUE/FALSE
logical evaluation returning TRUE/FALSE
logical evaluation returning TRUE/FALSE
logical evaluation returning TRUE/FALSE
logical evaluation returning TRUE/FALSE
logical evaluation returning TRUE/FALSE
logical evaluation returning TRUE/FALSE
logical evaluation returning TRUE/FALSE
logical evaluation returning TRUE/FALSE
logical evaluation returning TRUE/FALSE
coerces a numeric variable x into a factor variable
summary statistics (requires mosaic package)
sum of all elements in x
mean of all elements in x
median of x
standard deviation of all elements in x
minimum and maximum of x
minimum of x
maximum of x
min, Q1, median, mean, Q3, and max of x
calculate percentiles from data
apply a function over different levels of a categorical variable
apply a function over multiple grouping variables
missing data indicator for R
ignore missing data in x and return mean
table of frequencies for categorical data
relative percents for categorical data
contigency table (e.g., 2x2)
add margins to a table object my.tab
calculates row (margin=1) or column (margin=2) percentages
create scatterplot
add points to scatterplot
add line to scatterplot
plot columns of matrices (plot one x and multiple y)
produce a pie chart
produce a bar plot
produce a stem and leaf plot
produce a boxplot
produce side by side boxplots by levels of group variable
produce side by side boxplots by levels of >1 group variable
produce side by side boxplots of two different variables
histogram
qqplot
add line to qqplot
add legend to plot
matrix scatterplot
all R colors
all plotting options

DISTRIBUTIONS
pnorm(q,mean=0,sd=1,lower.tail=TRUE)
qnorm(p,mean=0,sd=1,lower.tail=TRUE)
rnorm(n,mean=0,sd=1)
dbinom(x,size,p)
pbinom(x,size,p,lower.tail=TRUE)
rbinom(n,size,p)
pt(q,df,lower.tail=TRUE)
qt(p,df,lower.tail=TRUE)
rt(n,df)
pchisq(q,df,lower.tail=TRUE)
INFERENCE
t.test(var,mu=0)
t.test(var~group)
t.test(var1,var2,paired=TRUE)
prop.test(x,n,p)
prop.test(x,n,correct=FALSE)
chisq.test(var1,var2,correct=FALSE)
cor(x,y)
cor.test(x,y)
linear.model1<-lm(y~x1+)
summary(linear.model1)
coef(linear.model1)
confint(linear.model1)
resid(linear.model1)
aov.model1<-aov(var~group)
anova(aov.model1)
TukeyHSD(aov.model1)
plot(TukeyHSD(aov.model1))
glm.1<-glm(y~x1+)

calculate a probability from normal distribution


calculate a quantile from normal distribution
generate n observations follow a normal distribution
calculate an exact probability from binomial distribution
calculate a cumulative probability from binomial distribution
generate n observations from binomial distribution
calculate a probability from t distribution
calculate a quantile from t distribution
generate n observations from a t distribution
calculate probability from a chi-squared distribution
one-sample t-test & CI
two-sample t-test & CI
paired t-test & CI
one-sample proportion test & CI
two-sample proportion test if x and n are vectors
chi-squared test
estimate correlation
perform significance test of correlation
linear model
summary of linear model
coefficient estimates
confidence intervals for coefficients
residuals from linear model
one-way ANOVA
anova table for model1
Tukey adjustment for multiple comparisons
plot of multiple comparisons
generalized linear model

You might also like