Philippe J. S. De Brouwer - The Big R-Book

Здесь есть возможность читать онлайн «Philippe J. S. De Brouwer - The Big R-Book» — ознакомительный отрывок электронной книги совершенно бесплатно, а после прочтения отрывка купить полную версию. В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: unrecognised, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.

The Big R-Book: краткое содержание, описание и аннотация

Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «The Big R-Book»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.

Introduces professionals and scientists to statistics and machine learning using the programming language R Written by and for practitioners, this book provides an overall introduction to R, focusing on tools and methods commonly used in data science, and placing emphasis on practice and business use. It covers a wide range of topics in a single volume, including big data, databases, statistical machine learning, data wrangling, data visualization, and the reporting of results. The topics covered are all important for someone with a science/math background that is looking to quickly learn several practical technologies to enter or transition to the growing field of data science. 
The Big R-Book for Professionals: From Data Science to Learning Machines and Reporting with R Provides a practical guide for non-experts with a focus on business users Contains a unique combination of topics including an introduction to R, machine learning, mathematical models, data wrangling, and reporting Uses a practical tone and integrates multiple topics in a coherent framework Demystifies the hype around machine learning and AI by enabling readers to understand the provided models and program them in R Shows readers how to visualize results in static and interactive reports Supplementary materials includes PDF slides based on the book’s content, as well as all the extracted R-code and is available to everyone on a Wiley Book Companion Site
is an excellent guide for science technology, engineering, or mathematics students who wish to make a successful transition from the academic world to the professional. It will also appeal to all young data scientists, quantitative analysts, and analytics professionals, as well as those who make mathematical models.

The Big R-Book — читать онлайн ознакомительный отрывок

Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «The Big R-Book», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

4.3.2 Vectors

4.3.2.1 Creating Vectors

Simply put, vectors are lists of objects that are all of the same type. They can be the result of a calculation or be declared with the function c().

vector

x <- c(2, 2.5, 4, 6) y <- c("apple", "pear") class(x) ## [1] "numeric" class(y) ## [1] "character"

More about lists can be found in Section 4.3.6 " Lists " on page 53.

4.3.3 Accessing Data from a Vector

In many situations you will need to address a vector as a whole, but there will also be many occasions where it is necessary to do something with just one element. Since this is such a common situation, R provides more than one way to get this done.

# Create v as a vector of the numbers one to 5:v <- c(1 :5) # Access elements via indexing:v[2] ## [1] 2 v[ c(1,5)] ## [1] 1 5 # Access via TRUE/FALSE:v[ c(TRUE,TRUE,FALSE,FALSE,TRUE)] ## [1] 1 2 5 # Access elements via names:v <- c("pear" = "green", "banana" = "yellow", "coconut" = "brown") v ## pear banana coconut ## "green" "yellow" "brown" v["banana"] ## banana ## "yellow" # Leave out certain elements:v[ c( -2, -3)] ## pear ## "green"

4.3.3.1 Vector Arithmetic

The standard behaviour for vector arithmetic in R is element per element. With “standard” we mean operators that do not appear between percentage signs (as in %.%for example).

v1 <- c(1,2,3) v2 <- c(4,5,6) # Standard arithmeticv1 +v2 ## [1] 5 7 9 v1 -v2 ## [1] -3 -3 -3 v1 *v2 ## [1] 4 10 18

картинка 20Warning – Not all operations are element per element

The dot-product and other non-element-per-element-operators are available via specialized operators such as %.%: see Section 4.4.1 “ Arithmetic Operators ” on page 75

4.3.3.2 Vector Recycling

Vector recycling refers to the fact that in case an operation is requested with one too short vector, that this vector will be concatenated with itself till it has the required length.

# Define a short and long vector:v1 <- c(1, 2, 3, 4, 5) v2 <- c(1, 2) # Note that R ‘recycles’ v2 to match the length of v1:v1 +v2 ## Warning in v1 + v2: longer object length is not a multiple of shorter object length ## [1] 2 4 4 6 6

картинка 21Warning – Vector recycling

This behaviour is most probably different from what the experienced programmer will expect. Not only we can add or multiply vectors of different nature (e.g. long and real), but also we can do arithmetic on vectors of different size. This is usually not what you have in mind, and does lead to programming mistakes. Do take an effort to avoid vector recycling by explicitly building vectors of the right size.

4.3.3.3 Reordering and Sorting

To sort a vector, we can use the function sort().

sorting

sort()

# Example 1:v1 <- c(1, -4, 2, 0, pi) sort(v1) ## [1] -4.000000 0.000000 1.000000 2.000000 3.141593 # Example 2: To make sorting meaningful, all variables are coerced to # the most complex type:v1 <- c(1 :3, 2 +2i) sort(v1) ## [1] 1+0i 2+0i 2+2i 3+0i # Sorting is per increasing numerical or alphabetical order:v3 <- c("January", "February", "March", "April") sort(v3) ## [1] "April" "February" "January" "March" # Sort order can be reversed: sort(v3, decreasing = TRUE) ## [1] "March" "January" "February" "April"

картинка 22Question #2 Temperature conversion

The time series nottem(from the package “datasets” that is usually loadedwhen R starts) contains the temperatures in Notthingham from 1920 to 1939 in Fahrenheit. Create a new object that contains a list of all temperatures in Celsius.

картинка 23Hint – Addressing the object nottem

Note that nottemis a time series object (see Chapter 10“ Time Series Analysis ” on page 255) and not a matrix. Its elements are addressed with nottam[n]where n is between 1 and length(nottam). However, when printed it will look like a matrix with months in the columns and years in the rows. This is because the print-function will use functionality specific to the time series object. a Remember that temperature length 434 Matrices Matrices are a very important - фото 24).

temperature

length()

4.3.4 Matrices

Matrices are a very important class of objects. They appear in all sorts of practical problems: investment portfolios, landscape rendering in games, image processing in the medical sector, fitting of neural networks, etc.

matrix

4.3.4.1 Creating Matrices

A matrix is in two-dimensional data set where all elements are of the same type. The matrix()function offers a convenient way to define it:

matrix()

# Create a matrix.M = matrix( c(1 :6), nrow = 2, ncol = 3, byrow = TRUE) print(M) ## [,1] [,2] [,3] ## [1,] 1 2 3 ## [2,] 4 5 6 M = matrix( c(1 :6), nrow = 2, ncol = 3, byrow = FALSE) print(M) ## [,1] [,2] [,3] ## [1,] 1 3 5 ## [2,] 2 4 6

It is also possible to create a unit or zero vector with the same function. If we supply one scalar instead a vector to the first argument of the function matrix(), it will be recycled as much as necessary.

matrix()

# Unit vector: matrix(1, 2, 1) ## [,1] ## [1,] 1 ## [2,] 1 # Zero matrix or vector: matrix(0, 2, 2) ## [,1] [,2] ## [1,] 0 0 ## [2,] 0 0 # Recycling also works for shorter vectors: matrix(1 :2, 4, 4) ## [,1] [,2] [,3] [,4] ## [1,] 1 1 1 1 ## [2,] 2 2 2 2 ## [3,] 1 1 1 1 ## [4,] 2 2 2 2 # Fortunately, R expects that the vector fits exactly n times in the matrix: matrix(1 :3, 4, 4) ## Warning in matrix(1:3, 4, 4): data length [3] is not a sub-multiple or multiple of the number of rows [4] ## [,1] [,2] [,3] [,4] ## [1,] 1 2 3 1 ## [2,] 2 3 1 2 ## [3,] 3 1 2 3 ## [4,] 1 2 3 1 # So, the previous was bound to fail.

4.3.4.2 Naming Rows and Columns

Читать дальше
Тёмная тема
Сбросить

Интервал:

Закладка:

Сделать

Похожие книги на «The Big R-Book»

Представляем Вашему вниманию похожие книги на «The Big R-Book» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.


Отзывы о книге «The Big R-Book»

Обсуждение, отзывы о книге «The Big R-Book» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.

x