# Adv Data Science using R Quiz and Assignment 1

**These are Advance Data Science Using R Assignment 1 Solution**

## Quiz

**Q1. How do you create a variable named x with the numeric value 5?**

int x=5

All of the above

x<-5

x : 5

**Answer: x<-5**

**Q2. How do you insert COMMENTS in R code?**

None

// This is a comment

/* This is a comment

**Answer: // This is a comment**

**Q3. What is a correct syntax to output “Hello World” in R?**

‘Hello World’

“Hello World”

print(“Hello World”)

All of the other answers are correct

**Answer: All of the other answers are correct**

**Q4. Who is introduced R Programming Language?**

Ross Ihaka

Robert Gentleman

Both (A) and (B)

Florian Hahne

**Answer: Both (A) and (B)**

**Q5. When the First appeared R Programming Language?**

August 1992

August 1994

August 1993

August 1995

**Answer: August 1993**

**Q6. Which function is often used to concatenate elements?**

join()

merge()

paste()

concat()

**Answer: paste()**

**Q7. Which statement is used to stop a loop?**

stop

exit

break

return

**Answer: break**

**Q8. Which function is used to find the amount of rows and columns in an array?**

dim()

nchar()

length()

dim_len()

**Answer: dim()**

**Q9. How do you start writing a while loop in R?**

while x < y:

x < y while

while x < y

while (x < y)

**Answer: while (x < y)**

**Q10. How do you start writing an if statement in R?**

if (x > y)

if x > y:

if x > y then:

None of the above

**Answer: if (x > y)**

**Q11. Which function is used to add additional columns in a matrix?**

add()

cbind()

join()

append_item()

**Answer: cbind()**

**Q12. Which function is used to draw points (markers) in a diagram?**

d()

draw()

plot()

canvas()

**Answer: plot()**

**Q13. How can you assign the same value to multiple variables in one line?**

var1, var2, var3 <- “Orange”

var1, var2, var3 = “Orange”

var1, var2, var3 => “Orange”

var1 <- var2 <- var3 <- “Orange”

**Answer: var1 <- var2 <- var3 <- “Orange”**

**Q14. Which operator is used to add together two values?**

The & sign

The + sign

The * sign

None of the above

**Answer: The + sign**

**Q15. The following values: 10.5, 55 and 787, belongs to which data type?**

numeric

integer

complex

All of the above

**Answer: numeric**

**These are Advance Data Science Using R Assignment 1 Solution**

## Assignment

**Q1. Explain Some of the Similarities and Differences Between R and Python.**

**Solution: **

#### Key Difference Between R and Python

- R is mainly used for statistical analysis while Python provides a more general approach to data science
- The primary objective of R is Data analysis and Statistics whereas the primary objective of Python is Deployment and Production
- R users mainly consists of Scholars and R&D professionals while Python users are mostly Programmers and Developers
- R provides flexibility to use available libraries whereas Python provides flexibility to construct new models from scratch
- R is difficult to learn at the beginning while Python is Linear and smooth to learn
- R is integrated to Run locally while Python is well-integrated with apps
- Both R and Python can handle huge size of database
- R can be used on the R Studio IDE while Python can be used on Spyder and Ipython Notebook IDEs
- R consists various packages and libraries like tidyverse, ggplot2, caret, zoo whereas Python consists packages and libraries like pandas, scipy, scikit-learn, TensorFlow, caret

**Q2. Write and Explain Some of the Most Common Syntaxes in R?**

**Solution: **

- In R, the primary assignment operator is
`<-`

as in:`x <- 3`

- Not
`x = 3`

- To add to the potential confusion, the equals sign actually
*can*be used as an assignment operator in R — most (but not all) of the time.

- One more note about variables: R is a case-sensitive language. So, variable x is not the same as X. That applies to just about everything in R; for example, the function
`subset()`

would not be the same as`Subset()`

. - To put multiple values into a single variable, you use the
`c()`

function, such as:`my_vector <- c(1, 1, 2, 3, 5, 8)`

- If you forget that
`c()`

, you’ll get an error.

- Performing a mathematical operation on a vector variable will automatically loop through each item in the vector. Many R functions are already vectorized, but others aren’t, and it’s important to know the difference.
`if()`

is not vectorized, for example, but there’s a version`ifelse()`

that is.

**Q3. (a) How Do You Assign a Variable in R?(b) List Some of the Best Packages For:i. Data Visualizationii. Data Miningiii. Data Imputation**

**Solution:**

(a):

There are different ways to define a variable in R which are:

- In R, a variable always starts with a letter or with a period. A variable if started with a dot cannot be succeeded by a number.
- Variables cannot be created with keywords which are already predefined in R; that is keywords which are reserved, as their names or identifiers.
- A variable in R can be defined using just letters or an underscore with letters, dots along with letters. We can even define variables as a mixture of digits, dot, underscore and letters.
- In R, a few instances of names of variables that are relevant are name, Var, var_1, .var, var.1

(b):

(i): Packages for ** Data Visualization**

- ggplot2.
- Lattice.
- highcharter.
- Leaflet.
- RColorBrewer.
- Plotly.
- sunburstR.
- RGL.

(ii): Packages for ** Data Mining**

reshape

sna social network analysis

tm: a framework for text mining applications

lda: fit topic models with LDA

topicmodels: fit topic models with LDA and CTM

RTextTools: automatic text classification via supervised

(iii): Packages for Data Imputation

- MICE
- Amelia
- missForest
- Hmisc
- mi

**These are Advance Data Science Using R Assignment 1 Solution**

Get more about R language here:

Advance Data Science using R all weeks assignments: Click Here

This content is uploaded for study, general information, and reference purpose only.