R Programming Language Basics

From Ittichai Chammavanijakul's Wiki
Revision as of 10:05, 9 March 2014 by Ittichai (talk | contribs)
Jump to navigation Jump to search
  • Set working directory
> setwd('~/Desktop/R_scripts')
  • Read data
> data=read.table('Statistic.csv')

# Need two backslashes for Windows file system
> data=read.table('C:\Documents\My R\Life Expentancy.txt')
Error: '\U' used without hex digits in character string starting "'C:\U"

> data=read.table('C:\\Documents\\My R\\Life Expectancy.txt')
  • Review data
> data
1    A    2.0
2    B    3.0
3    C    4.0
  • Assign a specific column to variable
> grade=data[,2]
  • Plotting
> plot(grade, xlab='Name', ylab='Score', ylim=c(1,3)
> boxplot(grade, xlab='Name', ylab='Score', ylim=c(1,3)
  • View basic arithmetic summary data
> summary
Min.