> setwd("/Users/morteza/Dropbox/academics/papers/presentations/neondsr/code/r") > source("osbs_14April15_data.R") Browse[2]> Q # to exit debug mode install.packages('knitr', dependencies = T)
library(knitr) http://www.math.umaine.edu/~hiebeler/comp/matlabR.pdf > help(boxplot) USE RStudio $ R > q() # To quit ------------------------------------------
Data frameData frame is an array of columns of different typesMake<-c("Honda","Chevrolet","Ford","Eagle","Volkswagen","Buick","Mitsbusihi",
"Dodge","Chrysler","Acura")
Model<-c("Civic","Beretta","Escort","Summit","Jetta","Le Sabre","Galant", "Grand Caravan","New Yorker","Legend") Cylinder<-c(rep("V4",5),"V6","V4",rep("V6",3)) Weight<-c(2170,2655,2345,2560,2330,3325,2745,3735,3450,3265) Mileage<-c(33,26,33,33,26,23,25,18,22,20) Type<-c("Sporty","Compact",rep("Small",3),"Large","Compact","Van",rep("Medium",2)) Car<-data.frame(Make,Model,Cylinder,Weight,Mileage,Type)
# combines the six vectors into a single
data frame.
names(Car) # "Make" "Model" "Cylinder"
"Weight" "Mileage" "Type"
Car[1,]
Car$Mileage
# get millage column. ==== Car[,5] > table(Car$Type) # table() command gives a frequency table:
> length(Car$Type) # vector length > table(Car$Make, Car$Type) # cross tabulation > i<-order(Car$Weight);i # ORDER BY WEIGHT
[1] 1 5 3 4 2 7 10
6 9 8
> Car[i,] > data1<-edit(data.frame())
# edit an empty frame in built in spreadsheet editor > hist(Car$Mileage)
> hist(Mileage, freq=F) # if probability instead of frequency is desired > data(faithful) > attach(faithful) # attach() allows to reference variables
in fuel.frame without the cumbersome fuel.frame$ prefix.
> names(faithful)
[1] "eruptions" "waiting"
> hist(eruptions, seq(1.6, 5.2, 0.2), prob=T)
> lines(density(eruptions, bw=0.1))
> rug(eruptions, side=1) > boxplot(Weight)
# usual vertical boxplot
> boxplot(Weight, horizontal=T) # horizontal boxplot > rug(Weight, side=2) Boxplot is more useful when comparing grouped data. For example, side-by-side boxplots of weights grouped by vehicle types are shown below: > boxplot(Weight ~Type) ; title("Weight by Vehicle Types") > plot(Weight) > plot(Weight, Mileage, main="Weight vs. Mileage") # a scatterplot with Weight on the x-axis and Mileage on the y-axis. R markdown which can include R code and display their results |