forked from qtran4/Exercise08
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExercise08_script.R
More file actions
34 lines (25 loc) · 1.02 KB
/
Exercise08_script.R
File metadata and controls
34 lines (25 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#Assumes working directory is set to Exercise08 directory
#1
#defines file to return and line to return
file_to_return <- read.csv("iris.csv",header=TRUE)
lines_to_return <- 10
#prints first few rows of the file based on desired line number
file_to_return[1:lines_to_return,]
#2
iris <- read.csv("iris.csv")
#prints last two rows in the last two columns of file
iris[(nrow(iris)-1):nrow(iris),(ncol(iris)-1):ncol(iris)]
#prints number of observations for each species in the dataset
length(which(iris$Species == "setosa"))
length(which(iris$Species == "versicolor"))
length(which(iris$Species == "virginica"))
#prints rows with Sepal.Width > 3.5
iris[iris$Sepal.Width>3.5,]
#writes data for setosa species to comma delimited file setosa.csv
setosa_data <- iris[iris$Species=="setosa",]
write.csv(setosa_data, file="setosa.csv")
#calculates mean, min, and max Petal.Length for virginica
virginica.data <- iris[iris$Species=="virginica",]
mean(virginica.data$Petal.Length)
min(virginica.data$Petal.Length)
max(virginica.data$Petal.Length)