Using R in this book
Some chapters have short R exercises that run in your browser. You are not going to learn to program: you will use R as a powerful calculator to look inside some information tools. This chapter explains just what you need in ten minutes.
- Run and modify R code in the browser.
- Store values and text in objects and work with vectors.
How the code cells work
Each code block has a Run Code button. You can change the code and run it again; Start Over restores the original version. The first time you open a page, the browser downloads the R engine (a few seconds).
<- stores a value in an object. A vector groups several values with c(). Text goes in quotation marks:
Exercise 1
A search returns 480 results and, after reviewing them, 24 are relevant. Calculate the proportion of relevant results (the precision of the search).
Replace the blank with the total number of results.
relevant <- 24
results <- 480
relevant / results0.05: only one result in twenty is useful. In the chapter on retrieval you will see how to improve precision.
Exercise 2
Check whether “Dialnet” is in the vector sources.
Write the name exactly as it appears, with a capital first letter.
"Dialnet" %in% sourcesTRUE. If you write “dialnet” in lower case, R says FALSE: it is case-sensitive, like some search engines.
Self-assessment
Answer all the questions and press Show answers: correct answers turn green, wrong ones red, and you will see your score. You can change your answers and check again. It does not count towards your mark.
- In R, text is written in quotation marks.
- To create a vector with several values you use the function
length(c("a", "b", "c"))returns- To do the exercises in this book you need to install R on your computer.
- Without quotation marks, R would look for an object with that name.
c()combines values into a vector.- Three elements.
- They run in the browser with webR.