Lesson 1: R & RStudio interface
Friday, December 22, 2023
Hello everyone, I’m Reddy.
I’m a PhD candidate specializing in Political Science at the University of Essex. My research delves into understanding authoritarian regimes, democratization, international conflict, coup d’état dynamics, and political economy.
As a Teaching Assistant for GV900–Introduction to Quantitative Methods & Data Analysis I, I’m excited to share my knowledge and help beginners navigate the world of R programming.
Let’s get started!
console
>
bottom right pane
top right pane
+
\[ 123 + 321 \]
Up Arrow: ⇪
History
[1] 1 2 3 4 5 6 7 8 9 10
[1] 1 11 21 31 41 51 61 71 81 91
[1] 1000 900 800 700 600 500 400 300 200 100
[1] 1.000000 4.807692 8.615385 12.423077 16.230769 20.038462
[7] 23.846154 27.653846 31.461538 35.269231 39.076923 42.884615
[13] 46.692308 50.500000 54.307692 58.115385 61.923077 65.730769
[19] 69.538462 73.346154 77.153846 80.961538 84.769231 88.576923
[25] 92.384615 96.192308 100.000000
[1] 1 3 5 1 3 5
[1] 1 1 3 3 5 5
[1] 9 88 65 9 47 25 34 19 43 88
[1] "Tail" "Head" "Tail" "Head" "Head" "Tail" "Tail" "Head" "Tail" "Tail"
[1] "Head" "Tail" "Head" "Head" "Tail" "Head" "Tail" "Tail" "Tail" "Head"
[1] "Tail" "Tail" "Tail" "Tail" "Tail" "Tail" "Head" "Tail" "Tail" "Tail"
test <- rbinom(n = 100,size = 10, prob = 0.5)
# This scenario is akin to tossing 10 fair coins, each with a probability of 0.5, a total of 100 times. As a result, we obtain a vector consisting of 100 numbers. Each number represents the count of 'Heads,' where 'Heads' is considered a successful outcome in this context.
test
[1] 4 6 5 6 4 3 5 4 7 4 5 5 4 5 5 7 3 8 4 6 5 5 6 5 2 5 7 6 7 2 6 2 7 4 2 7 5
[38] 5 8 4 3 4 6 6 2 5 3 6 6 7 5 4 4 4 7 6 5 9 5 9 7 5 6 6 6 1 7 7 7 2 3 7 5 4
[75] 4 7 3 3 7 6 4 6 3 4 3 6 3 6 5 4 2 5 4 3 4 5 7 6 7 6
test
1 2 3 4 5 6 7 8 9
1 7 11 19 21 20 17 2 2
Help
small vector Write code (in the R script, not in the console) to create a vector (using the combine function) called “small” that has numbers from 1 to 4, i.e., it has 4 values: 1, 2, 3 and 4.
big vector Next, create another vector called “big” that has values from 5 to 8.
third vector Now create a third vector called “sum” where you add small and big. Display the output of “sum.” What is the length of the vector called sum? Write the length in comments for yourself.
first vector of numbers Create a vector of numbers from 0 to 50 in increments of 5; store it as a variable called “first.”
second vector of numbers Create a variable called “second” that is a vector of numbers from 5 to 60, which is of the same length as the first vector.
add vectors Add the two vectors, naming the new vector “third.
vector of names Create a vector of six first names of politicians (real or hypothetical) and save them as a variable. Remember to name the variable.
sub vector Save the third, fourth, fifth names as a separate variable.
Thank you!