# Adv. Data Science Using R | Assignment – 1

**Quiz – 1**

**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

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

// This is a comment

/* This is a comment

None

**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**

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

Ross Ihaka

Robert Gentleman**Both (A) and (B)**

Florian Hahne

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

August 1992

August 1994**August 1993**

August 1995

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

join()

merge()**paste()**

concat()

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

stop

exit**break**

return

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

nchar()

length()

dim_len()

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

while x < y:

x < y while

while x < y**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

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

add()**cbind()**

join()

append_item()

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

d()

draw()**plot()**

canvas()

**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**

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

The & sign**The + sign**

The * sign

None of the above

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

integer

complex

All of the above

**Assignment – 1**

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

R and Python are both popular programming languages for data analysis and statistics. Some similarities between the two include:

- Both languages have extensive libraries for data manipulation, visualization, and modeling.
- Both are open-source and have a large user community, making it easy to find help and resources.

Some differences between R and Python include:

- R was developed specifically for statistics and data analysis, whereas Python is a general-purpose programming language that can be used for a wide range of tasks, including data analysis.
- R has a more limited set of data types compared to Python, which can make Python more versatile and easier to work with.
- R has a more expressive syntax, which allows for more concise code, but also makes it more difficult to read and understand. Python, on the other hand, has a more readable and consistent syntax.
- R has a more extensive set of libraries specifically designed for statistics and data analysis, while Python has a more extensive set of libraries for general purpose, machine learning and deep learning.

Both R and Python have their own strengths and weaknesses, and the best choice of language often depends on the specific task at hand and the user’s personal preferences.

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

Here are some common syntaxes in R:

- Assigning values to variables: To assign a value to a variable in R, use the assignment operator (=). For example, to assign the value 5 to a variable x, you would use the following syntax: x = 5.
- Creating a vector: To create a vector in R, use the c() function. For example, to create a vector containing the numbers 1, 2, and 3, you would use the following syntax: c(1, 2, 3).
- Indexing a vector: To access a specific element of a vector in R, use square brackets and the index of the element. For example, to access the second element of a vector x, you would use the following syntax: x[2].
- Creating a matrix: To create a matrix in R, use the matrix() function. For example, to create a matrix with 2 rows and 3 columns, containing the numbers 1, 2, 3, 4, 5, and 6, you would use the following syntax: matrix(c(1, 2, 3, 4, 5, 6), nrow = 2, ncol = 3).
- Indexing a matrix: To access a specific element of a matrix in R, use square brackets and the row and column indices of the element. For example, to access the element in the second row and third column of a matrix x, you would use the following syntax: x[2, 3].
- Performing calculations: To perform calculations in R, use the standard mathematical operators. For example, to add two numbers x and y, you would use the following syntax: x + y.
- Creating a function: To create a function in R, use the function() function. For example, to create a function that takes a single argument and squares it, you would use the following syntax:

```
square <- function(x) {
x^2
}
```

- if-else statement: To create an if-else statement in R, use the if() and else() functions. For example, to check if a variable x is greater than 5, you would use the following syntax:

```
if(x > 5) {
print("x is greater than 5")
} else {
print("x is not greater than 5")
}
```

These are some of the most common syntaxes in R and provide a good starting point for working with R. However, keep in mind that R has a rich set of functions and tools available, and you may find yourself using other syntaxes as you continue to work with the language.

**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**

(a) In R, you can assign a value to a variable using the assignment operator (=). The variable name is placed on the left side of the operator and the value to be assigned is placed on the right side. For example, to assign the value 5 to a variable x, you would use the following syntax:

x <- 5 greeting <- "Hello, World!" y <- x

**x = 5** {You can also use the ‘=’ operator for assignment in R, for example}

Keep in mind that when a value is assigned to a variable, it overwrites the previous value of that variable. so be careful when reusing the same variable names in your R script.

**(b) Some of the Best Packages are:**

**i. Data Visualization:**

- Matplotlib
- Seaborn
- Plotly
- Bokeh
- ggplot
- Altair

**ii. Data Mining:**

- scikit-learn
- Rasa
- NLTK
- Gensim
- Orange
- RapidMiner

**iii. Data Imputation:**

- pandas
- MICE (Multiple Imputation by Chained Equations)
- Amelia
- FancyImpute
- sklearn.impute