# thercast/basic-interaction-with-R

Switch branches/tags
Nothing to show
Fetching contributors…
Cannot retrieve contributors at this time
69 lines (51 sloc) 2.08 KB
 #---------------------------------------------------------------------------------------------- # File: basic-session-code.R # Date: 03-04-2012 # Author: Eric Nantz # URL: https://github.com/thercast/basic-interaction-with-R/blob/master/basic-session-code.R # Email: theRcast@gmail.com # Purpose: Example of a basic R session demonstrated in the R-Podcast episode 3 # www.r-podcast.org/the-r-podcast-episode-3-basic-interaction-with-r # License: Creative Commons Attribution-ShareAlike 3.0 Unported License #---------------------------------------------------------------------------------------------- # Try entering the following commands in the R Console one line at a time 2+3 pi*(6^2) # a numeric vector can be created using the c() function # for example, six high school GPA scores: c(3.67, 3.95, 2.89, 4.00, 3.83, 3.18) # Using assignment sequence <- or = to assign this vector to an object called x x <- c(3.67, 3.95, 2.89, 4.00, 3.83, 3.18) x = c(3.67, 3.95, 2.89, 4.00, 3.83, 3.18) x # access certain elements of the vector using [n] where n is index of desired element x[1] # count the number of elements in x using the length() function length(x) # compute the mean using the mean() function mean(x) # access the help page for mean to see if a trimmed mean can be computed # the following commands are equivalent help(mean) ?mean # many functions have examples that can be run by using the example function example(mean) # use the trim argument to get a trimmed mean mean(x, trim=1/6) # equivalent to the following x.sorted <- sort(x) x.trimmed <- x.sorted[c(-1,-6)] mean(x.trimmed) # other statistics can be calculated using the summary function summary(x) # a simple scatterplot can be generated by the plot function plot(x) # to install packages from command line, use install.packages function install.packages("ggplot2") # to load a package from command line, use the library function library(ggplot2) # to save workspace from command line, use the save.image or save function save.image(file="myWorkspaceAll.RData") save(x, file="myWorkspaceSubset.RData") # to quit R, use q() q()