Example R programs and commands 1. Data lists; mean and median # All lines preceded by the "#" character are my comments. # All other left-justified lines are my input. # All other indented lines are the R program output. # To enter a list of data into a variable named "x" x <- c(1.1, 2.0, 1.5, 2.1, 1.9, 1.8) # NOTE: "<-" means assignment; read it as "gets". "=" can be used as well. # To display the value of "x" x [1] 1.1 2.0 1.5 2.1 1.9 1.8 # Number of elements in the list named "x" length(x) [1] 6 # Sum of all elements in "x" sum(x) [1] 10.4 # Arithmetic mean mean(x) [1] 1.733333 sum(x)/length(x) [1] 1.733333 # Proportional median median(x) [1] 1.85 # Concatenate two lists y <- c(3.5, 3.6, 3.7); c(x,y) # semicolons separate commands [1] 1.1 2.0 1.5 2.1 1.9 1.8 3.5 3.6 3.7 z <- c(x,y); z [1] 1.1 2.0 1.5 2.1 1.9 1.8 3.5 3.6 3.7