Go back to the main page
Go back to the R overview page
This file can be downloaded here
R Basics
- Create a vector with elements 1, 2, 3. Assign to variable
vec1.
- Calculate the length of the vector.
- What class type is the vector?
- Calculate the mean.
- Calculate the median.
- Calculate the standard deviation.
- Create a vector with elements 1 to 10. Use the
:notation. Assign to variablevec2.
- Create a sequence of 1 to 10. Only odd numbers. Assign to variable
vec3.
- create a vector from vector
arepeated 10 times. Assign tovec4
- Use the
pastefunction to concatenate stringshelloandworld.
- Use the
paste0function to concatenate stringshelloandworld.
- Print all letters of the alphabet.
- Print all letters of the alphabet in capitals.
- Assign all letters of the alphabet to
vec5.
- Use
toupperfunction to convert letters to capitals.
- Select first element of
vec5.
- Select all but the first element of
vec5.
- Print last 6 elements of
vec5.
- Print last element of
vec5.
- Create a factor “G”, “V”, “O”, “V”, “G”. Add levels and order.
Assign to
fac1.
- Print all elements larger than “V” from
fac1.
- Create vector 1, 2, 3. Assign to
vec6. Add 1 to each element.
- Create vector one, 2, 3. Assign to
vec7. What class is this vector?
- Create a data frame
df1of two columns: 1, 2, 3 and 4, 5, 6.
- Add column names “col1” and “col2”.
- Add column
col3that consist of vector 7, 8, 9.
- Select the second column by index.
- Select the second column by name.
- Select the first column by index in [, ] notation.
- Select the third column by index in [, ] notation.
- Create
df2with columnscol4,col5andcol6. Assign to vectors c(10, 11, 12), c(13, 14, 15), c(16, 17, 18).
- Sum the data frames
df1anddf2.
- Add 1 to all values of
col3.
- Print
col3.
- Add 1 to all values of
col3and save to df3.
- Print the build in data frame
iris.
- Get help on data frame
iris.
- Print the Petal Length by index.
- Print the second row from the third column.
- Print the Petal Length by column name.
- Print the second item from the column Petal Length.
- Print the max Petal Length.
- Print a logical vector for all the values in Petal Length equal to the max value.
- Print the row in
iriscorresponding to the max Petal Length.
- Print summary statistics of
iris.
- Print summary statistics of the Petal Length column in
iris.
- Print all the rows equal to species
virginicainiris.
- Order the data frame based on Petal Length. Order ascending.
- Order the data frame based on Petal Length. Order descending.
- Create XY-scatter of vectors: x = c(1, 2, 3), y = c(4, 5, 6)
- Create XY-scatter of
irisSepal Length against Petal With.
- Again but with title and axis labels. Use whatever text you like.Blue dots.
- Create histogram of
irisSepal Lenght.
- Again but with breaks of 0.25
- Create boxplot of
irisSepal Length andirisSepal Width. Give labels (names) “sepal length” and “sepal width”.
- Create XY-scatter with y = c(1, 2, 3) and x = c(4, 5, 6) using the formula notation.
- Create a barplot of vector c(1, 2, 3).
- Create a barplot of vector c(1, 2, 3). Labels (names) = a, b, c.
- Print the build in data frame
ChickWeight.
- Create XY-scatter of weight plotted against Time from data frame ChickWeight. Use formula notation.
- Create a linair regression model. Print model to screen.
- Create XY-scatter of weight plotted against Time from data frame ChickWeight. Use formula notation. Display the regression line.
- Plot the
irisSepal Length against Sepal Width in blue. Also add a second series to the plot.this should be Petal Length against Petal Width in red.
- Create a line plot of x = c(1, 2, 3) and y = c(4, 5, 6) in blue.Add second series x = c(1, 2, 3) and y = c(5, 5.5, 6) in red.
The end…
Go back to the main page
Go back to the R overview page
⬆️ Back to Top
This web page is distributed under the terms of the Creative Commons Attribution License which permits unrestricted use, distribution, and reproduction in any medium, provided the original author and source are credited. Creative Commons License: CC BY-SA 4.0.