1.1. Data in R 3 Box 1.1. Using the snippet( ) function If you have installed the fastR package (and any other additional packages that may be needed for a particular example), you can execute the code from this book on your own computer using snippet(). For example, snippet(’iris-str’) will both display and execute the first code block on page 2, and snippet(’iris-str’, exec=FALSE) will display the code without executing it. Keep in mind that some code blocks assume that prior blocks have already been executed and will not work as expected if this is not true. [129] 6.4 7.2 7.4 7.9 6.4 6.3 6.1 7.7 6.3 6.4 6.0 6.9 6.7 6.9 5.8 6.8 [145] 6.7 6.7 6.3 6.5 6.2 5.9 iris-vector2 iris$Species # get one variable and print as vector [1] setosa setosa setosa setosa setosa [6] setosa setosa setosa setosa setosa [11] setosa setosa setosa setosa setosa 19 lines removed [111] virginica virginica virginica virginica virginica [116] virginica virginica virginica virginica virginica [121] virginica virginica virginica virginica virginica [126] virginica virginica virginica virginica virginica [131] virginica virginica virginica virginica virginica [136] virginica virginica virginica virginica virginica [141] virginica virginica virginica virginica virginica [146] virginica virginica virginica virginica virginica Levels: setosa versicolor virginica This is not a particularly good way to get a feel for data. There are a number of graphical and numerical summaries of a variable or set of variables that are usually preferred to merely listing all the values especially if the data set is large. That is the topic of our next section. It is important to note that the name iris is not reserved in R for this data set. There is nothing to prevent you from storing something else with that name. If you do, you will no longer have access to the iris data set unless you first reload it, at which point the previous contents of iris are lost. iris-reload iris - ’An iris is a beautiful flower.’ str(iris) chr "An iris is a beautiful flower." data(iris) # explicitly reload the data set str(iris) ’data.frame’: 150 obs. of 5 variables: $ Sepal.Length:num 5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ... $ Sepal.Width :num 3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
Previous Page Next Page