---
title: "Lab 1 - Introduction"
author: "Tera"
date: "August 2017"
output: html_document
---

```{r setup, include=FALSE}

#if echo=TRUE then the source code is included in the output file, if echo=FALSE then only the output is in the output file

library(knitr)
knitr::opts_chunk$set(echo = T)
```

```{r reading in other data files and some basic functions}

#set the working directory (wd) to the folder that contains the script file, and read in the data
x <- getwd()
setwd(x)

Dataset <- read.table("schooldays.csv", sep=',', header=TRUE)

#see first and last 6 rows of data
head(Dataset)
tail(Dataset)

#see whole dataset (or click on the same of the dataset in the Environment window)
View(Dataset)

#output the structure of the dataset
str(Dataset)

#output the variable names
names(Dataset)

#compute descriptive statistics for all variables or a single variable
summary(Dataset)
summary(Dataset$race)

#output type of data structure
class(Dataset)

```

```{r create new variable and output data frame}

attach(Dataset)

#create variable that is -1 times the value for absent
Dataset$absent.inverse <- -1*absent

#create a variable that is 180 minus the value for absent
Dataset$present <- 180-absent

head(Dataset)

#output file with new variables
write.csv(Dataset, "newvariables.csv", row.names=FALSE)
```
