Download An Introduction to R Software for Statistical Modelling & by Kuhnert&Venable PDF

By Kuhnert&Venable

Show description

Read or Download An Introduction to R Software for Statistical Modelling & Computing PDF

Best compilers books

Visual Language Theory

Kim Marriott Bernd Meyer communique is without doubt one of the hallmarks of people. once we give some thought to hu­ guy communique, most folks first consider spoken and written lan­ guages. those are related in that symbols within the language are encountered and processed sequentially, both temporally as they're spoken or as char­ acters are learn throughout a web page.

Construction and Evolution of Code Generators: A Model-Driven and Service-Oriented Approach

Automated code new release is an important cornerstone of model-driven techniques to software program improvement. at present, plenty of recommendations can be found that aid the specification and implementation of code turbines, reminiscent of engines according to templates or rule-based modifications. All these options have in universal that code turbines are both without delay programmed or defined by way of textual requirements.

Extra info for An Introduction to R Software for Statistical Modelling & Computing

Sample text

Names(L1) <- c("Item1","Item2","Item3") Indexing lists can be achieved in a similar way to how data frames are indexed: c CSIRO Australia, 2005 Course Materials and Exercises R Objects 58 > L1$Item1[L1$Item1>2] [1] 4 3 4 5 3 3 3 5 3 3 5 Joining two lists can be achieved either using the concatenation function or the append function. The following two scripts show how to join two lists together using both functions. Concatenation function: > L2 <- list(x=c(1,5,6,7), y=c("apple","orange","melon","grapes")) > c(L1,L2) $Item1 [1] 2 4 3 4 1 5 3 1 1 2 3 3 5 2 1 3 2 3 5 1 $Item2 [1] "a" "b" "c" "d" "e" "a" "b" "c" "d" "e" "a" "b" [13]"c" "d" "e" "a" "b" "c" "d" "e" $Item3 [1] 0 0 2 1 1 0 2 0 0 1 1 1 0 0 1 1 1 3 0 2 $x [1] 1 5 6 7 $y [1] "apple" "orange" "melon" "grapes" Append Function: > append(L1,L2,after=2) $Item1 [1] 2 4 3 4 1 5 3 1 1 2 3 3 5 2 1 3 2 3 5 1 $Item2 [1] "a" "b" "c" "d" "e" "a" "b" "c" "d" "e" "a" [12]"b" "c" "d" "e" "a" "b" "c" "d" "e" $x [1] 1 5 6 7 c CSIRO Australia, 2005 Course Materials and Exercises R Objects 59 $y [1] "apple" "orange" "melon" "grapes" $Item3 [1] 0 0 2 1 1 0 2 0 0 1 1 1 0 0 1 1 1 3 0 2 Adding elements to a list can be achieved by • adding a new component name: > L1$Item4 <- c("apple","orange","melon","grapes") # alternative way > L1[["Item4"]] <- c("apple","orange","melon","grapes") • adding a new component element, whose index is greater than the length of the list L1[[4]] <- c("apple","orange","melon","grapes") > names(L1)[4] <- c("Item4") There are also many functions within R that produce a list as output.

The following example extracts the first component only. > L1[1] $x [1] 2 1 1 4 5 3 4 5 5 3 3 3 4 3 2 3 3 2 3 1 Working with Lists The length of a list is equal to the number of components in that list. So in the previous example, the number of components in L1 equals 3. We confirm this result using the following line of code: > length(L1) [1] 3 To determine the names assigned to a list, the names function can be used. Names of lists can also be altered in a similar way to that shown for data frames.

Df. df$Species <- factor(rep(Snames,rep(50,3))) To check that we have created the data frame correctly, we print out the first five rows of the data frame. df[1:5,] Sepal L. Sepal W. Petal L. Petal W. 2 Setosa c CSIRO Australia, 2005 Course Materials and Exercises R Objects 53 A pairwise plot of the data (Figure 18) can be produced using the pairs function in the following way. 5 Sepal L. 5 6 7 Sepal W. 5 1 2 3 4 Petal L. Petal W. 5 1 2 3 4 5 6 7 Figure 18: Pairwise plot of the iris data frame Accessing Elements of a Vector or Matrix Accessing elements is achieved through a process called indexing.

Download PDF sample

Rated 4.14 of 5 – based on 44 votes