2016年1月7日星期四

R Graphs 1

用R 來plot graph


Get data from: http://aqsdr1.epa.gov/aqsweb/aqstmp/airdata/download_files.html
Annual Summary Data > annual_all_2015.zip

pollution<-read .csv="" annual_all_2015.csv="" character="" colclasses="c(" data="" read--="" sep=",">
> PM25<-pollution -="" arameter.name="=" conditions="" font="" local="" pollution="">
> PM25<-pm25 aily="" etric.used="=" font="" mean="">
> PM25.mean<-as .numeric="" font="" rithmetic.mean="">
> summary(PM25.mean)

[1] "8.868966" "8.868966" "8.990909" "8.990909" "9.01"     "9.01"  
> summary(PM25.mean)
   Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
 0.5839  7.0650  8.7450  8.6970 10.2000 37.9100 
 

Boxplot

 
> boxplot(PM25.mean,col="blue")


Histogram

 
 
> hist(PM25.mean, col="green")
 
 
 
 
> hist(PM25.mean, col="green")
> rug(PM25.mean)
> hist(PM25.mean, col="green", breaks=100)
> rug(PM25.mean)
 
 
 

Overlaying feature

> boxplot(PM25.mean,col="blue")
> abline(h=12)
> hist(PM25.mean, col="green")
> abline(v=12,lwd=2)
> abline(v = median(PM25.mean), col="red", lwd=4)



2015年12月29日星期二

R data type

介紹 R 的data type

Vector


可儲起多個相同data type 的object.




如不同data type 的object mix在一起,R 會自動把object 的data type 轉變為同一種data type (這叫coercion)




Matrix


Matrix 可想像成由column 組成. 數字由左上往下排列,然後 往右再組成新的column。




 

cbind and rbind


 

List


類似vector 但可支援不同data type



R - Introduction and installation

R basics

R  是一種Programming language,主要用於statistics, plot graph 和date mining 等等。

Install R

從以下URL 可下載R
https://cran.rstudio.com/

下載R Studio
https://www.rstudio.com/products/rstudio/download/



Get the working directory