

We don’t need to specify the number of rows / columns as these are defined by the data we use to create the data frame. We will use the ame() function to do this. Call the first column colour and the second one weight. Join the two vectors into a data frame called containing 2 columns and 4 rows.lour # "red"Įnter some numerical weight data (supplied in the question) into a vector called mouse.weight c(23,21,18,26) -> mouse.weight This is a simple selection with a single index position. Display the second element in the vector.Because the data we are entering is text we need to surround each name with quotes so that R doesn’t try to treat it as a variable name. We will use the c() function to manually make this vector. Enter a list of colours (supplied in the question) into a vector called lour.
C1 V1 C2 V2 TRAINING SERIES
The second one is an integer series so we can use the 10:30 notation to make this quickly. The first one is small enough that you could make it manually with c() or as it’s a series you could use seq() to make it. Inside the square brackets you put a vector of index positions, so the problem here is to create the vector of index positions. Extract the values at positions 10 to 30īoth of these require making a selection in the vector using the notation.Extract the values at positions 5,10,15 and 20 in the vector of values you just created.As we’re using this in the next exercise we will save it into a new variable. We need to supply the from, by and length.out parameters to seq to create this series. Use seq() to make a vector of 100 values starting at 2 and increasing by 3 each time.Subtract vec2 from vec1 and look at the resultīecause we have the same number of values in both vec1 and vec2 the equivalent positions will be paired up and we will see the subtraction results from the same positions, ie 2-5, 5-6, 8-7 etc.

