Basic R Flashcards
Get subset of data
subset(mdata = cdc, gender == “m” & age > 40)
Compute the relative frequency distribution for gender in dataset
table(cdc$gender) / 20000(totalnumberofdata) = males 52,1%
compute interquartile range
Subtract Q1 from Q3 to find the interquartile range.
help.search()
Help search
get a summary and use descriptive stastistics in dataset
summary(dataset)
main =
edit the header text of graph
col =
color your graph
all_equal()
all_equal() allows you to compare data frames, optionally ignoring row and column names.
Prop =
Compute proportions, percents, or counts for a single level
Ctable ()
Cross-tabulation for a pair of categorical variables (or factors) with either row, column, or total proportions, as well as marginal sums
range()
R has a function range which applied to a vector v returns a two-component vector comprising the minimal and maximal component of v.
var
Variance is the spread a variable around the means.
R has a function var for computing the variance.
pnorm()
Calculating percentiles - using computation
> pnorm(1800, mean = 1500, sd = 300)
[1] 0.8413447
Define a function
Create a function to print squares of numbers in sequence.
new.function
Simulations in R
Use the sample() function to determine the probability of rolling a 7 using three fair six-sided dies.
trials