#---------------------
# Practice R Session
# 10/11/2012
#---------------------
#
1+2
# compute area
width=20.0
height= 5.0
area = width*height
# some random features
sqrt(16)
c(3,4,5,6,7,8)
help(sqrt) # this is how to get help
help.search("mean") # this searches the help index
# these are strings
'this is a string'
"this is also a string"
a='todd'
a+10
# collections of numbers
group1 = c(1,2,3,4,5,6,7,8,9)
group2 = c(11,12,13,14,15,16,17,18,19)
length(group1) # this is the length
group1and2 = c(group1, group2)
group1 + 10 # add 10 to all the numbers
sqrt(group1) # sqrt of all the numbers
diff=group1-group2 # computes difference
group12[2] # access subelement of vector
group2[2:4] # access range
# hand coded selection
groupSEL = c(TRUE,FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE)
group2[groupSEL]
# computed selection
groupSEL = group2<14
group2[groupSEL] # gives us all the numbers less than 14
# data frames!!!!!!
subjnum = c(1,2,3,4,5)
cond = c("c1", "c2", "c1", "c2", "c1")
RT = c(350, 400, 500, 456, 234)
mydf = data.frame(subjnum, cond, RT)
mtcars # this is the builtin dataframe with car info
mydf[2,3] # gets second row, third col
mydf[2,"RT"] # gets second row, RT col
mydf$RT # gets RT col as a vector
mtcars["Mazda RX4","cyl"] # access particular entries
mydf$RT<=400
#reading data frames from file
library(gdata)
mydf2=read.xls("myfilename.xls")