## Read comma-separated-version file (csv) ## The first line is the header (header = TRUE) ## The first col contains the row names (row.names = 1) getwd() setwd("/u/kalisch/teaching/12/ams/R/v1.1/") x <- read.csv(file = "USairpollution.csv", header = TRUE, row.names = 1) ## ?read.csv if you need more info on the function "read.csv" ## This help page explains the xa set ?USairpollution ## get an overview of the structure of the data head(x) dim(x) str(x) ################################################## ## mean ################################################## cm <- colMeans(x) cm ################################################## ## covariance and correlation ################################################## ## Is there a (linear) association between SO2 and manu? plot(x$manu, x$SO2) ## Scatterplot cov(x$manu, x$SO2) ## Covariance: depends on units of measurement cor(x$manu, x$SO2) ## Correlation: does not depend on that cor.test(x$manu, x$SO2, method = "pearson") ## cor.test(x$manu, x$SO2, method = "spearman") ## What about all pairs of variables plot(x) ## Scatterplotmatrix S <- cov(x) ## Covariance matrix; save for later use S cor(x) ## Correlation matrix ## Parallel Coordinate Plot parcoord(x) ## Stars Plot stars(x) stars(x, key.loc = c(15,1.5), flip.labels = FALSE, draw.segment = TRUE) ## Bubble Plot plot(x$temp, x$SO2, pch = 20) symbols(x$temp, x$SO2, circles = x$manu, add = TRUE) ################################################## ## Mixed data ################################################## library(MVA) tmp <- read.csv("/sfs/u/staff/kalisch/teaching/12/ams/R/v1.2/australian-crabs.csv") head(tmp) dim(tmp) x <- tmp[,-3] head(x) str(x) specNumeric <- as.numeric(x$species) sexNumeric <- as.numeric(x$sex) parcoord(x[,3:7], col = specNumeric) parcoord(x[,3:7], col = sexNumeric) ## get's easily too crowded ...