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] 81 88 26 71 89 99 55 21 67 63
[1] "Tail" "Tail" "Tail" "Tail" "Head" "Tail" "Head" "Tail" "Tail" "Head"
[1] "Tail" "Head" "Tail" "Tail" "Head" "Tail" "Head" "Tail" "Tail" "Tail"
[1] "Tail" "Tail" "Head" "Tail" "Tail" "Head" "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 5 7 7 5 6 5 7 6 4 3 3 6 5 5 7 6 3 4 6 5 2 3 4 4 3 6 8 4 5 5 5 7 5 6 6 6
[38] 6 6 6 5 5 3 7 5 6 7 4 4 6 5 8 3 3 3 6 7 6 3 8 7 4 7 7 3 2 7 8 4 5 7 5 4 3
[75] 5 6 6 6 6 5 3 4 7 5 4 2 7 5 5 3 8 7 4 4 8 6 3 6 6 5
test
2 3 4 5 6 7 8
3 15 15 22 23 16 6
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!