Skip to content

doesmindmatter/NeuralDynamics-RTutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

NDL R Tutorial

author: Ryan Mears date: March 24, 2014 transition: linear

Overview

[Tutorial Webpage][Tutorial webpage] [Tutorial webpage]: http://doesmindmatter.github.io/NeuralDynamics-RTutorial

Working with data in R with the RStudio GUI

  • Get and Shape data into tidy arrangements
  • Analyze and Summarize data with R packages
  • Explore and Present with data visualization and publication quality tables and plots

Installing R and RStudio

type: section

R

Install [R][R-prog] [R-Prog]: http://cran.us.r-project.org/

![The R Foundation for Statistical Computing][cranr] [cranr]: NDL_R_tutorial-figure/CranR.png "The R Foundation for Statistical Computing"

RStudio

Install [RStudio][RS-Prog] [RS-Prog]: http://www.rstudio.com/ide/download/desktop

![RStudio][cranr] [cranr]: NDL_R_tutorial-figure/rstudio-mac.png "RStudio"

Get and Shape Data

type: section

Reading Data and Code

  • read.csv()
getwd()
  • source()
getwd()

Data and Code in R

Create variables

- c() ```{r} hc_subjs <- c('sbj101','sbj102','sbj105') sz_subjs <- c('sbj103','sbj104','sbj106') ``` - seq() - seq_len(6) `r seq_len(6) ` - seq(from = -2, to = 3, by = 1) `r seq(from = -2, to = 3, by = 1) ` - rep() - rep(c('HC','SZ'), times = 1, each = 3) `r rep(c('HC','SZ'), times = 1, each = 3) ` - rep(c('HC','SZ'), times = 3, each = 1) `r rep(c('HC','SZ'), times = 3, each = 1) `

Create variables

x <- seq_len(6)
subjs <- c(hc_subjs,sz_subjs)
cbind(x,subjs)

Create variables

  • cbind()
  hc_2 <- cbind(hc_subjs,"hc")
  sz_2 <- cbind(sz_subjs,"sz")
  sz_2

  • rbind()
 grp_subjs <- rbind(hc_2,sz_2)
  colnames(grp_subjs)<-c("subj","group")
  grp_subjs

Examine variables

  • print()
print(hc_subjs)
  • length()
length(hc_subjs)
  • dim()
dim(grp_subjs)

  • str()
str(grp_subjs)

Index and Select

  • Indices
grp_subjs[1,1]
grp_subjs[1,]

  • Booleans
grp_subjs[,2]=='hc'

Index and Select

  • grep(), grepl(), gsub(), substr()

Convert and Combine

  • paste(), paste0(), cat()
  • join()
  • expand.grid()

Subset and Reshape

  • filter()
  • select()
  • reshape()
  • melt()
  • cast()
  • **ply()

Analyze and Summarize

type: section

Compute Parameters

  • mutate()

Compare Means

  • ttest()

ANOVA

  • ezANOVA()
plot(cars)

Explore and Present

type: section

Plot

  • plot()
  • ggplot()
  • ggvis()

Present Results for Publication

  • stargazer()

Dynamic Documents

  • knit()

Resources

type: subsection