Skip to content

Commit

Permalink
Sync changes done for 3rd pages on another folder
Browse files Browse the repository at this point in the history
  • Loading branch information
aphalo committed Apr 21, 2020
1 parent 6c135f8 commit c6e8fe0
Show file tree
Hide file tree
Showing 20 changed files with 313,419 additions and 288,825 deletions.
10 changes: 5 additions & 5 deletions R.as.calculator.Rnw
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ opts_knit$set(concordance=TRUE)
opts_knit$set(unnamed.chunk.label = 'calculator-chunk')
@

\chapter{The R language: ``words'' and ``sentences''}\label{chap:R:as:calc}
\chapter{The R language: ``Words'' and ``sentences''}\label{chap:R:as:calc}

\begin{VF}
The desire to economize time and mental effort in arithmetical computations, and to eliminate human liability to error, is probably as old as the science of arithmetic itself.
Expand Down Expand Up @@ -36,7 +36,7 @@ In later chapters you will learn how to write compound statements, the equivalen

\section{Numeric values and arithmetic}
\index{classes and modes!numeric, integer, double|(}\index{numbers and their arithmetic|(}\qRclass{numeric}\index{math operators}\index{math functions}\index{numeric values}\qRoperator{+}\qRoperator{-}\qRoperator{*}\qRoperator{/}
When working in \Rlang with arithmetic expressions, the normal mathematical precedence rules are respected, but parentheses can be used to alter this order. Parentheses can be nested, but in contrast to the usual practice in mathematics, the same parenthesis symbol is used at all nesting levels.
When working in \Rlang with arithmetic expressions, the normal mathematical precedence rules are respected, but parentheses can be used to alter this order. Parentheses can be nested, but in contrast to the usual practice in mathematics, the same parenthesis symbol is used at all nesting levels.

\begin{explainbox}
Both in mathematics and programming languages \emph{operator precedence rules} determine which subexpressions are evaluated first and which later. Contrary to primitive electronic calculators, \Rlang evaluates numeric expressions containing operators according to the rules of mathematics. In the expression $3 + 2 \times 3$, the product $2 \times 3$ has precedence over the addition, and is evaluated first, yielding as the result of the whole expression, 9. In programming languages, similar rules apply to all operators, even those taking as operands non-numeric values.
Expand Down Expand Up @@ -1431,7 +1431,7 @@ a.list
@

\subsection{Member extraction and subsetting}
Using\qRoperator{[[]]}\index{lists!member extraction|(}\index{lists!member indexing|see{member extraction}}\index{lists!indexes|see{member extraction}} double square brackets for indexing a list extracts the element stored in the list, in its original mode. In the example above, \code{a.list[["x"]]} returns a numeric vector, while \code{a.list[1]} returns a list containing the numeric vector \code{x}. \code{a.list\$x} returns the same value as \code{a.list[["x"]]}, a numeric vector. \code{a.list[c(1,3)]} returns a list of length two, while \code{a.list[[c(1,3)]]} is an error.
Using\qRoperator{[[]]}\index{lists!member extraction|(}\index{lists!member indexing|see{lists!member extraction}} double square brackets for indexing a list extracts the element stored in the list, in its original mode. In the example above, \code{a.list[["x"]]} returns a numeric vector, while \code{a.list[1]} returns a list containing the numeric vector \code{x}. \code{a.list\$x} returns the same value as \code{a.list[["x"]]}, a numeric vector. \code{a.list[c(1,3)]} returns a list of length two, while \code{a.list[[c(1,3)]]} is an error.

<<lists-1>>=
a.list$x
Expand Down Expand Up @@ -1764,15 +1764,15 @@ detach(my_data_frame.df)
head(my_data_frame.df, 2)
@

In the case of \Rscoping{with()} only one, possibly compound code statement is affected and this statement is passed as an argument. As before, we need to fully specify the left-hand side of the assignment. The value returned is the one returned by the statement passed as an argument, in the case of compound statements, the value returned by the last contained simple code statement to be executed. Consequently, if the intent is to modify the container, assignment to an individual member variable (column in this case) is required. In contrast to the behavior of \code{attach()}, in this case column \code{A} of \code{my\_data\_frame.df} takes precedence, and the returned value is the expected one.
In the case of \Rscoping{with()} only one, possibly compound code statement is affected and this statement is passed as an argument. As before, we need to fully specify the left-hand side of the assignment. The value returned is the one returned by the statement passed as an argument, in the case of compound statements, the value returned by the last contained simple code statement to be executed. Consequently, if the intent is to modify the container, assignment to an individual member variable (column in this case) is required. In contrast to the behavior of \code{attach()}, In this case, column \code{A} of \code{my\_data\_frame.df} takes precedence, and the returned value is the expected one.

<<data-frames-EB-12>>=
my_data_frame.df$C <- NULL
my_data_frame.df$C <- with(my_data_frame.df, (A + B) / A)
head(my_data_frame.df, 2)
@

In the case of \Rscoping{within()}, assignments in the argument to its second parameter affect the object returned, which is a copy of the container (in this case a whole data frame), which still needs to be saved through assignment. Here the intention is to modify it, so we assign it back to the same name, but it could have been assigned to a different name so as not to overwrite the original data frame.
In the case of \Rscoping{within()}, assignments in the argument to its second parameter affect the object returned, which is a copy of the container (In this case, a whole data frame), which still needs to be saved through assignment. Here the intention is to modify it, so we assign it back to the same name, but it could have been assigned to a different name so as not to overwrite the original data frame.

<<data-frames-EB-13>>=
my_data_frame.df$C <- NULL
Expand Down
2 changes: 1 addition & 1 deletion R.data.Rnw
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ Function \Rfunction{arrange()} is used for sorting the rows---makes sorting a da
arrange(long_iris.tb, Species, plant_part, part_dim)
@

Function \Rfunction{filter()} can be used to extract a subset of rows---similar to \Rfunction{subset()} but with a syntax consistent with that of other functions in the \pkgname{tidyverse}. In this case 300 out of the original 600 rows are retained.
Function \Rfunction{filter()} can be used to extract a subset of rows---similar to \Rfunction{subset()} but with a syntax consistent with that of other functions in the \pkgname{tidyverse}. In this case, 300 out of the original 600 rows are retained.

<<tidy-tibble-04>>=
filter(long_iris.tb, plant_part == "Petal")
Expand Down
10 changes: 5 additions & 5 deletions R.data.io.Rnw
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ Text files containing data in columns can be divided into two broad groups. Thos

In the first example we will read a file with fields solely delimited by ``,.'' This is what is called comma-separated-values (CSV) format which can be read and written with \Rfunction{read.csv()} and \Rfunction{write.csv()}, respectively.

Example file \code{not-aligned-ASCII-UK.csv} contains.
Example file \code{not-aligned-ASCII-UK.csv} contains:

<<file-io-csv-00a, comment='', echo=FALSE>>=
cat(readLines("extdata/not-aligned-ASCII-UK.csv"), sep = "\n")
Expand Down Expand Up @@ -471,7 +471,7 @@ write_excel_csv(my.df, path = "my-file6.csv")
file.show("my-file6.csv", pager = "console")
@

That saves a file containing the following text.
That saves a file containing the following text:
<<readr-11, comment='', echo=FALSE>>=
cat(read_lines('my-file6.csv'), sep = '\n')
@
Expand Down Expand Up @@ -573,7 +573,7 @@ sheets <- excel_sheets("extdata/Book1.xlsx")
sheets
@

In this case the argument passed to \code{sheet} is redundant, as there is only a single worksheet in the file. It is possible to use either the name of the sheet or a positional index (in this case \code{1} would be equivalent to \code{"my data"}). We use function \Rfunction{read\_excel()} to import the worksheet. Being part of the \pkgname{tidyverse} the returned value is a tibble and character columns are returned as is.
In this case, the argument passed to \code{sheet} is redundant, as there is only a single worksheet in the file. It is possible to use either the name of the sheet or a positional index (in this case \code{1} would be equivalent to \code{"my data"}). We use function \Rfunction{read\_excel()} to import the worksheet. Being part of the \pkgname{tidyverse} the returned value is a tibble and character columns are returned as is.

<<readxl-02>>=
Book1.df <- read_excel("extdata/Book1.xlsx", sheet = "my data")
Expand Down Expand Up @@ -690,7 +690,7 @@ my_spss.tb <- read_sav(file = "extdata/my-data.sav")
my_spss.tb[1:6, c(1:6, 17)]
@

In this case the dates are correctly decoded.
In this case, the dates are correctly decoded.

Next, we import an \pgrmname{SPSS}'s \code{.sav} file saved 15 years ago.

Expand Down Expand Up @@ -868,7 +868,7 @@ remote_my_spss.tb <-
remote_my_spss.tb
@

In this example we use a downloaded NetCDF file of long-term means for potential evapotranspiration from NOOA, the same used above in the \pkgname{ncdf4} example. This is a moderately large file at 444~KB. In this case we cannot directly open the connection to the NetCDF file, and we first download it (commented out code, as we have a local copy), and then we open the local file.
In this example we use a downloaded NetCDF file of long-term means for potential evapotranspiration from NOOA, the same used above in the \pkgname{ncdf4} example. This is a moderately large file at 444~KB. In this case, we cannot directly open the connection to the NetCDF file, and we first download it (commented out code, as we have a local copy), and then we open the local file.

<<url-05, eval=eval_online_data>>=
my.url <- paste("ftp://ftp.cdc.noaa.gov/Datasets/ncep.reanalysis.derived/",
Expand Down
2 changes: 1 addition & 1 deletion R.functions.Rnw
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ opts_knit$set(concordance=TRUE)
opts_knit$set(unnamed.chunk.label = 'functions-chunk')
@

\chapter{The R language: adding new ``words''}\label{chap:R:functions}
\chapter{The R language: Adding new ``words''}\label{chap:R:functions}

\begin{VF}
Computer Science is a science of abstraction---creating the right model for a problem and devising the appropriate mechanizable techniques to solve it.
Expand Down
Loading

0 comments on commit c6e8fe0

Please sign in to comment.