0% found this document useful (0 votes)
5 views6 pages

Psy 202 CA2

Uploaded by

elhannin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views6 pages

Psy 202 CA2

Uploaded by

elhannin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

FA24 Psy 202 Sections 2 & 7 Conceptual Assignment 2

1. What is R?
R is an object-oriented language used to analyze and visualize data. It treats informa on as
objects— that are mostly numbers. It is used for sta s cal compu ng and analyses. It is domain-
speci c and a very popular sta s cal so ware. It can be installed on a for convenient use.

2. Dr. Navarro iden ed ve bene ts of using R to teach sta s cs. What were those ve
bene ts?
1. Using R on the computer is faster, easier, and more e cient. The computer performs well at
repe ve tasks and sta s cs.
2. Using R rather than a spreadsheet like Microso Excel allows you to have ample opportuni es
to perform sta s cs. Excel is limited in the types of analyses it can do.
3. Rather than se ling for an expensive student package of so ware, R is an open source and is
also free to everyone.
4. R is highly extensible in that it has become a standard tool as it is used by many people. R is
used in advanced textbooks. Learning and using R would be bene cial in helping to
understand other sta s cal analyses that also use R.
5. As programming is a core research skill used in various social and behavioral sciences, learning
R is a great way to start learning sta s cs as it is a real programming language. Anyone “doing
research in psychology” would nd using R to be very bene cial.

3. Why is using RStudio preferable to using the default R GUI?


It allows us to work more easily and e ciently with R. There is a code editor, workspace &
history, R console, and plots and les. R Studio color codes for easier understanding. Posit Cloud
is also an online version of R-studio.

4. In R, what does the > mean at the start of a line?


“>” at the start of a line means that R is wai ng for the next set of codes.

5. Why would programmers making typographical errors be a problem for R?


R will always do what the programmer tells it to do, but it may not be what the programmer
intended for it to do, which is why it is so important for programmers to correctly type out their
set of codes.

6. In which situa ons would changing spacing in R a ect its output?


Changing spacing by inser ng a space in the middle of a word would a ect the output of R.
In which situa ons would changing spacing in R not a ect its output?
R is able to ignore redundant spacing and if spaces are inserted between the word and the word
and the parenthesis or inside the parenthesis the output would not be a ected.
ti
fi
fi
ti
ti
ti
tt
ti
ti
ti
fi
ti
ti
ti
fi
ti
ti
ti
fi
ti
fi
fi
ti
ffi
ti
ft
ti
ft
ti
ffi
ti
ff
ff
fi
ft
ti
fi
ti
ti
ff
ff
ti
ti
fi
7. If there’s a + at the start of a line in R, what does that mean?
A “+” at the start of a line in R means that R is wai ng for you to nish. R is smart enough to
know that a code is not complete so R is reminding you to “add” whatever is next.

8. R can be used to do simple calcula ons. Describe in words what the following lines of
code tell R to do:

10 + 2 R would nd the sum of 10 and 2 by adding the number to nd 12 as the answer.

10 – 2 R would nd the di erence of 10 and 2 by subtrac ng 2 from 10 to get the answer 8.

10 * 2 R would nd the product of mul plying 10 and 2 to get 20.

10 / 2 R would divide 10 by 2 to nd the quo ent of 5.

10 ^ 2 The code is telling R to nd the answer of 10 squared, or to the second power, and the
product would be 100.

9. Although R recognizes the order of opera ons, we o en use parentheses when


performing mul ple calcula ons. Why?
R follows the basic order of opera ons (BEDMAS) and R goes from le to right. However, we
o en use parenthesis to perform mul ple calcula ons so R knows what we want it to priori ze.
By adding parenthesis, there is more clarity in the equa on and prevents errors.

10. In R, what is a variable?


A variable is where informa on is stored. Conceptually speaking, variables can be considered a
“label.” All of the data will be stored as variables in R. The variables in R can be a simple, single
value, or a complex opera on. The whole point of having variables is that anything can be done
with a variable that we can do with the informa on that is stored.

11. We can assign values to variables in R using the -> and <- assignment operators.
Describe what the following lines of code tell R to do:

sheep <- 45 The code is telling R to take the value of whatever is behind that arrow and
assign it to whatever is in front of the arrow, “sheep” would be assigned to “45”.

50 -> clone The code is telling R to take the value of what is on the le and assign it to
the value on the right, meaning “50” would be assigned to the “clone”.

clone <- sheep The code tells R to change the value of “sheep” and assign it to “clone”
leading to the value of “cone” being 45, rather than 50.

12. R can perform opera ons on variables as well as on individual values. If we tell R to
run the code sheep <- 45 and then run 50 -> clone, what does it do when we
tell it to run sheep + clone?
ft
ti
fi
fi
fi
ti
ti
ti
ff
ti
fi
ti
fi
ti
ti
ti
ti
ti
ti
ti
ti
ti
ft
ti
fi
ft
fi
ft
ti
When we tell R to run “sheep + cone,” R will perform an addi on equa on using 45 and 50 to
return 95 as the answer.

13. Like all programming languages, R has formal rules and informal conven ons for
naming variables. What are ve formal rules that Dr. Navarro iden ed?
1. Variable names can only use uppercase and lowercase le ers along with the numbers 0-9 in
the name. You can also use periods (.) or underscores (_), but no other characters. For
example, D_og.s works as a name but dogs! does not.
2. Spaces cannot be used in variable names. Ex: GO REBS is not valid, but GO_REBS is.
3. The names are case-sensi ve— DOGS and Dogs are di erent.
4. Variable names can only start with a le er or a period, but star ng with a period (.) is not
always conven onal. “_cats” is not a variable name.
5. Reserved keywords cannot be used as a variable name. Key words including “if, else, repeat,
func on, in, break, FALSE, TRUE, Inf, NA, while, for, next, NaN, NA_interger_, NA_complex_,
NA_real_, and NA_character_” cannot be used.
What are three informal conven ons that Dr. Navarro iden ed?
1. Use informa ve variable names— using meaningful names is easier to understand and keep
up with.
2. Use short variable names to avoid painful long names that take up space and me.
3. Use a conven onal naming style for variables that are mul -words. You can separate words in
mul -word variables by using underscores or periods. You can also use capital le ers to
represent the start of a word.

14. Within R programming, what is a func on?


Func ons are commands we give to R. Even func ons’ func ons have func ons. Func ons
perform speci c tasks and take input data — called arguments — to produce an output.
Func ons accomplish the necessary ac ons in R.
What is an argument?
Arguments are pieces of informa on you put into func ons and appear inside the parenthesis.
The arguments are the values that are passed to the func on when called. The argument is
typed into the func on. There can be more than one.
How do default values relate to arguments in a func on?
Default values relate to arguments in a func on because default values are evaluated inside the
func on. When the argument is not speci ed, the default values act as a fallback.
Because the digits argument has a default value of 0, R will act as if you had typed digits = 0.

15. How does RStudio make using func ons easier for programmers?
ti
ti
ti
ti
ti
ti
ti
fi
ti
ti
ti
fi
ti
ti
tt
ti
ti
fi
ti
ti
ti
ti
ff
ti
tt
ti
ti
ti
ti
ti
fi
ti
ti
ti
ti
fi
ti
ti
tt
ti
Rstudio has autocomplete ability, meaning that, while you type the func on, Rstudio gives you
various op ons of what R might expect you to type, making it easier and quicker. R also
automa cally keeps track of your “command history” which makes it easier to use func ons.

16. What is a vector in R?


Vectors are variables that can store mul ple values. A vector is the basic data structure that
stores data of similar types. Vectors can be a bunch of scores, a bunch of di erent values that
roll of the same type. Vectors also have elements.
What are elements?
Elements are part of a vector that are similar data types. There can be many elements in a
vector. Each element in a vector is an individual value at a speci c posi on within the vector.
What does it mean to index a vector?
All vectors have an address, and that address is their index. It is where they are located within
the vector. If you are going to index a vector, you are reques ng whatever informa on is at the
par cular loca on within the vector.

17. Variables in R usually store one of three classes of data. What are: *22 mins in video
…numeric data? Numerical data can be used in mathema cal opera ons: simple calcula ons,
using func ons to do calcula ons (like by using PEMDAS),
…character data? Character data includes le ers, words, and symbols
…logical data? Logical data reports if a statement is true or not. There are many logical data
operators

18. What does # mean in an R script?


The # tells R that anything that appears to the right of it is a comment, and anything on the le
of the # is part of the code.

19. What are R packages?


We can load data and func ons from packages. These packages can be downloaded from the
internet allowing R to perform and get things we otherwise would not have
What is the di erence between installing a package and loading a package?
When installing a package, you have to enclose the name within quota on marks. The install dot
packages func on needs a character string as its argument. When loading a package, a library is
required to successfully load it.

20. For which type of data do we need to use factors in R?


Nominal scores use factors in R.
Why do we use factors with that type of data?
ti
ti
ti
ti
ti
ff
ti
ti
ti
ti
tt
ti
ti
fi
ti
ti
ti
ti
ff
ti
ti
ti
ft
When dealing with nominal scores, you must explicitly tell R that the scores are nominal by
turning the scores into factors.

21. What are data frames?


Data frames help try to see what problem it solves. Data frames are tabular data structures used
to store values of any data type.
What does $ mean in reference to a data frame?
In reference to a data frame, $ is the operator used to extract the variable you’re interested in.
How do lists di er from data frames?
Lists can have components of the same or di erent types of components or modes. You can
assign names to each element in a list. A data frame is a list with an equal number of “rows” on
each column.

22. Iden fy what the following logical operators do:


< The quan ty on the le is less than the quan ty on the right.

<= The quan ty on the le is less than or equal to the quan ty on the right

> The quan ty on the le is more than the quan ty on the right.

>= The quan ty on the le is greater than or equal to the quan ty on the right

== This stands for “equal to.” This is the equality operator that forces R to determine if it is true
or false.

!= This stands for “not.” If both statements on the right and le are not equal, this is used.

! The ! stands for “not.”

| Read this as “or”

& Are both the statements on the le and right of the “&” are true

23. Iden fy what the following R func ons do:

sqrt() This func on nds the square root of the number in the parenthesis.

abs() This func on is used to return the absolute value of a number.

round() This func on rounds the number to the nearest integer.

c() This func on is used for crea ng and combining vectors.

length() This is used to get the length of the vector in R.

as.factor() Used to convert an input into a factor.


ti
ti
ti
ti
ti
ti
ff
ti
ti
ti
ti
fi
ft
ft
ft
ft
ti
ft
ti
ff
ti
ti
ti
ft
ti
install.packages() Used to take a vector of names and a library to download a
package from a repository and install it.

library() This func on is used to install packages.

attach() Used to access variables of a DataFrame without involving any func on or


method.

detach() This is used to remove the a achment in the data framework that was made by
the a ach () func on.
tt
ti
ti
tt
ti

You might also like