Biology Reference
In-Depth Information
(b)
> summary(iris)
> dim(iris)
(c)
> par(mfrow = c(1, 3))
> hist(iris[iris[, "Species"] == "setosa",
+ "Sepal.Length"],
+ xlab = "length", main = "Setosa Sepal Length")
> hist(iris[iris[, "Species"] == "versicolor",
+
"Sepal.Length"],
+ xlab = "length",
+ main = "Versicolor Sepal Length")
> hist(iris[iris[, "Species"] == "virginica",
+
"Sepal.Length"],
+ xlab = "length",
+ main = "Virginica Sepal Length")
(d)
> boxplot(Sepal.Length ˜ Species, data = iris)
1.4
Consider again the
iris
data set from Exercise
1.3
.
(a) Write the data frame holding
iris
data frame into a space-separated
text file named “iris.txt”, and read it back into a second data frame called
iris2
.
(b) Check that
iris
and
iris2
are identical.
(c) Repeat the previous two steps with a file compressed with
bzip2
named
“iris.txt.bz2”.
(d) Save
iris
directly (e.g., without converting it to a text table) into a file
called “iris.rda”, and read it back.
(e) List all
R
objects in the global environment, and remove all of them apart
from
iris
.
(f) Exit the
R
saving the contents of the current session.
(a)
> write.table(iris, file = "iris.txt",
+ row.names = FALSE)
> iris2 = read.table("iris.txt", header = TRUE)
(b)
> identical(iris, iris2)
(c)
> bzfd = bzfile("iris.txt.bz2", open = "w")
> write.table(iris, file = bzfd, row.names = FALSE)
> close(bzfd)
> bzfd = bzfile("iris.txt.bz2", open = "r")
> iris2 = read.table(bzfd, header = TRUE)
> close(bzfd)
> identical(iris, iris2)
(d)
> save(iris, file = "iris.rda")
> load("iris.rda")
(e)
> ls()
> l = ls()
> rm(list = l[l != "iris"])
Search WWH ::
Custom Search