Statistics and Statistical Programming (Winter 2017)/R lecture outline: Week 3: Difference between revisions

From CommunityData
No edit summary
 
(7 intermediate revisions by the same user not shown)
Line 1: Line 1:
* problems folks ran into:
== Review of material from class ==
** loading data:
 
*** load() versus read.csv()
* loading data:
*** when things don't coopreate...
** load() versus read.csv()
*** library(foreign)  
** when things don't coopreate...
* other things that have come up
** library(foreign)  
** dates with POSIXct(). dates will almost always be given to you as characters, and you need to parse them
* defining functions
** ordered() — really just a type of factor for ordinal data
** syntax for defining functions: show the my.mean function
* new things that are going to be very useful
** calling functions (your own or others) with apply(), lapply(), sapply()
** defining functions
** merge()
* looping
** apply(), lapply(), sapply()
** for looping
* stuff related to distributions
* stuff related to distributions
** rep()
** rep()
** seq()
** seq()
** sample()
** sample(); and sampling into data.frames
** distribution functions: lets focus on *unif(): the key is on page 222 of Verzani
 
*** The “d” functions return the p.d.f. of the distribution
== Online only ==
**** dunif(x=1, min=0, max=3) # 1/3 of the area is the to the left 1
 
*** The “p” functions return the c.d.f. of the distribution.
* dates with POSIXct(). dates will almost always be given to you as characters, and you need to parse them
**** dunif(q=2, min=0, max=3) #1/(b-a) is 2/3
* tapply(), and putting things back into data.frames
*** The “q” functions return the quantiles.
* merge()
**** qunif(p=0.5, min=0, max=3) # half way between 0 and 3
*** The “r” functions return random samples from a distribution.
**** runif(n=1, min=0, max=3) # a random value in [0,3]

Latest revision as of 19:38, 25 January 2017

Review of material from class[edit]

  • loading data:
    • load() versus read.csv()
    • when things don't coopreate...
    • library(foreign)
  • defining functions
    • syntax for defining functions: show the my.mean function
    • calling functions (your own or others) with apply(), lapply(), sapply()
  • stuff related to distributions
    • rep()
    • seq()
    • sample(); and sampling into data.frames

Online only[edit]

  • dates with POSIXct(). dates will almost always be given to you as characters, and you need to parse them
  • tapply(), and putting things back into data.frames
  • merge()