Regular Sequences
R-exercises | Train like you fight, fight like you train
by Han de Vries
5y ago
So far in this series, we used vectors from built-in datasets (rivers, women and nhtemp), or created them by stringing together several numbers with the c function (e.g. c(1, 2, 3, 4)). R offers an extremely useful shortcut to create vectors of the latter kind, which is the colon : operator. Instead of having to type: x <- c(1, 2, 3, 4) we can simply type x <- 1:4 to create exactly the same vector. Obviously this is especially useful for longer sequences. In fact, you will use sequences like this a lot in real-world applications of R, e.g. to select subsets of data points, records, or va ..read more
Visit website
Vectors and Functions
R-exercises | Train like you fight, fight like you train
by Han de Vries
5y ago
In the previous set we started with arithmetic operations on vectors. We’ll take this a step further now, by practising functions to summarize, sort and round the elements of a vector. Sofar, the functions we have practised (log, sqrt, exp, sin, cos, and acos) always return a vector with the same length as the input vector. In other words, the function is applied element by element to the elements of the input vector. Not all functions behave this way though. For example, the function min(x) returns a single value (the minimum of all values in x), regardless of whether x has length 1, 100 or 1 ..read more
Visit website
Working With Vectors
R-exercises | Train like you fight, fight like you train
by Han de Vries
5y ago
In the previous exercise set we practised vectors as a data structure. As I noted at the beginning of that set, perhaps you were already familiar with data in a vector-like structure in other applications such as Microsoft Excel or SPSS. If so, perhaps you also used those data to carry out calculations. In this set, we’re going to practise all sorts of calculations with vectors, from basic operations like addition and multiplication to somewhat more advanced arithmetics. This is the second set in a series of five: In the first set (posted last week) we practised the basics of vectors. In set t ..read more
Visit website
Creating vectors
R-exercises | Train like you fight, fight like you train
by Han de Vries
5y ago
A vector is the most elementary way to store and structure data in R. For now, think of it as a list of numbers, which can be as short as a single number, or as long as about 2 billion(!) numbers. Perhaps you were used to working with lists of numbers already in a spreadsheet application (E.g., a row or column filled with numbers in Microsoft Excel), or statistics package (e.g. a numeric variable in SPSS or SAS). However, in R, vectors have so many applications that go beyond the use of data in the examples I just mentioned. R vectors are the basic building blocks underlying the most fancy das ..read more
Visit website

Follow R-exercises | Train like you fight, fight like you train on FeedSpot

Continue with Google
Continue with Apple
OR