{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Lecture 1: Introduction into R data analysis\n", "\n", "First, import some data into a data structure using the READ command." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "options(repr.plot.width=10, repr.plot.height=6.5) # this command just formats the size of the figures. Adapt to view them nicely\n", " # in your browser." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "mydatastructure = read.csv(\"YieldStrengthData.csv\") # read csv file \n", "mydata = mydatastructure$YieldStrength" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "mydatastructure" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot(mydata,rep(0,length(mydata)), # plot(x,y) ; command rep = repeat. \n", " xlab=\"Yield Strength (MPa)\",\n", " ylab=\" \",\n", " col=\"blue\"\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Histograms" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hist(mydata,\n", " breaks = seq(floor(min(mydata)),ceiling(max(mydata)),by=1),\n", " plot=TRUE, \n", " axes=TRUE, \n", " xlab=\"Yield Strength (MPa)\",\n", " col=\"orange\",\n", " freq=TRUE)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Empirical Cumulative Distribution Function (ECDF)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot(ecdf(mydata))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Mean vs. Median" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "plot(mydata,rep(0,length(mydata)), # plot(x,y) ; command rep = repeat. \n", " xlab=\"Yield Strength (MPa)\",\n", " ylab=\" \",\n", " col=\"blue\"\n", " )\n", "abline(v=mean(mydata), col=\"red\",lwd=3)\n", "mtext(paste(\"mean=\", signif(mean(mydata),4)),col=\"red\")\n", "abline(v=median(mydata), col=\"blue\",lwd=3)\n", "mtext(paste(\"median=\", signif(median(mydata),4)),col=\"blue\",adj = 0)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# some random data\n", "mydata <- rnorm(n = 1000,mean = 13,sd = 9)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# bipartite data\n", "mydata <- c(rnorm(50,10,3),rnorm(5,300,0.3))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# asymmetric data\n", "mydata <- c(rnorm(300,20,5),rnorm(150,40,10))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Quantiles" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "quantile(mydata, probs = c(0,0.1,0.3,0.4,0.5,0.75,1))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Our first Boxplot" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "boxplot(mydata)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "R", "language": "R", "name": "ir" }, "language_info": { "codemirror_mode": "r", "file_extension": ".r", "mimetype": "text/x-r-source", "name": "R", "pygments_lexer": "r", "version": "3.6.3" } }, "nbformat": 4, "nbformat_minor": 4 }