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», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.

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

Интервал:

Закладка:

Сделать

It is possible to have more than one else-if statement and/or use nested statements.

x <-122 if(x < 10) { print(‘less than ten’)} else if(x <100) { print(‘between10 and100 ’)} else if(x <1000) { print(‘between 100 and 1000’) } else{ print(‘bigger than1000 (or equal to1000 )’)} ## [1] “between 10 and 1000”

Note that the statements do not necessarily have to be encapsulated by curly brackets if the statement only takes one line.

x <-TRUE y <-pi y <- if(x) 1 else2 y # y is now 1## [1] 1

Note that hybrid forms are possible, but it gets confusing very fast. In the following piece of code the variable ywill not get the value one, but rather six.

z <-y <- if(x) {1; z <-6} else2 y # y is now 6## [1] 6 z # z is also 6## [1] 6

4.5.1.2 The Vectorised If-statement

The function ifelse()is the vectorised version of the if-function. It allows to use vectors as input and output. While the if-statement is useful for controlling flow in code, the ifelse-function handy for data manipulation.

ifelse()

x <-1 :6 ifelse(x %%2 ==0, ‘even’, ‘odd’) ## [1] “odd” “even” “odd” “even” “odd” “even”

The ifelsefunction can also use vectors as parameters in the output.

x <-1 :6 y <-LETTERS[1 :3] ifelse(x %%2 ==0, ‘even’, y) ## [1] “A” “even” “C” “even” “B” “even” # Note that y gets recycled!

4.5.1.3 The Switch-statement

An if-else construct that assigns one value to a variable based on one other variable can be condensed via the switch()function.

switch()

x <-‘b’ x_info <- switch(x, ‘a’ = “One”, ‘b’ = “Two”, ‘c’ = “Three”, stop(“Error: invalid `x` value”) ) # x_info should be ‘two’ now:x_info ## [1] “Two”

The switch statement can always be written a an else-if statement. The following code does the same as the aforementioned code.

x <-‘b’ x_info <- if(x ==‘a’ ) { “One” } else if(x ==‘b’) { “Two” } else if(x ==‘c’) { “Three” } else{ stop(“Error: invalid `x` value”) } # x_info should be ‘two’ now:x_info ## [1] “Two”

The switch()statement can always be written as with the if-else-if construction, which in its turn can always be written based on with if-else statements. This is same logic also applies for loops (that repeat parts of code). All loop constructs can always be written with a for-loop and an if-statement, but more advanced structures help to keep code clean and readable.

4.5.2 Loops

One of the most common constructs in programming is repeating a certain block of code a few times. This repeating of code is a “loop.” Loops can repeat code a fixed number of times or do this only when certain conditions are fulfilled.

4.5.2.1 The For Loop

for

loop – for

As in most programming languages, there is a “for-loop” that repeats a certain block of code a given number of times. Interestingly, the counter does not have to follow a pre-defined increment, the counter will rather follow the values supplied in a vector. R's for-loop is an important tool to add to your toolbox.

The for-loop is useful to repeat a block of code a certain number of times. R will iterate a given variable through elements of a vector.

Function use for for()

for(value invector) { statements }

The for-loop will execute the statements for each value in the given vector.

Example: For loop

x <-LETTERS[1 :5] for( j inx) { print(j) } ## [1] “A” ## [1] “B” ## [1] “C” ## [1] “D” ## [1] “E”

картинка 50Note – No counter in the for loop

Unlike most computer languages, R does not need to use a “counter” to use a for-loop.

x <- c(0, 1, -1, 102, 102) for( j inx) { print(j) } ## [1] 0 ## [1] 1 ## [1] -1 ## [1] 102 ## [1] 102

4.5.2.2 Repeat

repeat()

The repeat-loop will repeat the block of commands till it executes the breakcommand.

loop – repeat

Function use for repeat()

repeat{ commands if(condition) { break} }

Example: Repeat loop

x <- c(1,2) c <-2 repeat{ print(x +c) c <-c +1 if(c >4) { break} } ## [1] 3 4 ## [1] 4 5 ## [1] 5 6

картинка 51Warning – Break out of he repeat loop

Do not forget the {break} statement, it is integral part of the repeat loop.

4.5.2.3 While

The while-loop is similar to the repeat-loop. However, the while-loop will first check the condition and then run the code to be repeated. So, this code might not be executed at all.

while

loop – while

Function use for while()

while(test_expression) { statement }

The statements are executed as long the test_expression is TRUE.

Example: While loop

x <- c(1,2); c <-2 while(c <4) { print(x +c) c <-c +1 } ## [1] 3 4 ## [1] 4 5

4.5.2.4 Loop Control Statements

When the breakstatement is encountered inside a loop, that loop is immediately terminated and program control resumes at the next statement following the loop.

break

v <- c(1 :5) for(j inv) { if(j ==3) { print(“--break--”) break} print(j) } ## [1] 1 ## [1] 2 ## [1] “--break--”

The nextstatement will skip the remainder of the current iteration of a loop and starts next iteration of the loop.

v <- c(1 :5) for(j inv) { if(j ==3) { print(“--skip--”) next} print(j) } ## [1] 1 ## [1] 2 ## [1] “--skip--” ## [1] 4 ## [1] 5

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

Интервал:

Закладка:

Сделать

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

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


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

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

x