Important R Language MCQs ggplot2 with Answers 8

The quiz “R Language MCQS ggplot2” will help you check your ability to execute some basic operations on objects in the R language, and it will also help you understand some basic concepts. This quiz may also improve your computational understanding.

Quiz about R Language

1. Data analysts are working with customer information from their company’s sales data. The first and last names are in separate columns, but they want to create one column with both names instead. Which of the following functions can they use?

 
 
 
 

2. Write the R commands for generating 700 random variables from normal distribution by using the following information: Mean = 14, SD = 3, n = 5, k = 2000.

 
 
 
 

3. For the population y<-c(1,2,3,4,5), write the R command to find the mean?

 
 
 
 

4. For the population y<-c(1,2,3,4,5), write the R command to find the median?

 

 
 
 
 

5. Which R function can be used to make changes to a data frame?

 
 
 
 

6. You are cleaning a data frame with improperly formatted column names. To clean the data frame you want to use the clean_names() function. Which column names will be changed using the clean_names() with default parameters?

 
 
 
 

7. Which of the following are standards of tidy data?

 
 
 
 

8. Which is the R command for obtaining 1000 random numbers through normal distribution with mean 0 and variance 1?

 
 
 
 

9. Let us have 1000 random samples of size 6 under SRSWOR using the following population (111, 150, 121, 198, 112, 136, 114, 129, 117, 115, 186, 110, 121, 115, 114) which is the R command for repeating this procedure 1500 times?

 
 
 
 

10. When programming in R, what is a pipe used as an alternative for?

 
 
 
 

11. Which summary functions can you use to preview data frames in R Language?

 
 
 
 

12. Suppose you want to simulate a coin toss 20 times in R. Write the command.

 
 
 
 

13. A data scientist is trying to print a data frame but when you print the data frame to the console output produces too many rows and columns to be readable. What could they use instead of a data frame to make printing more readable?

 
 
 
 

14. How sampling with and without replacement can be done using R?

 
 
 
 

15. Why are tibbles a useful variation of data frames?

 
 
 
 

16. In R the following are all atomic data types EXCEPT:

 
 
 
 

17. Data analysts are cleaning their data in R. They want to be sure that their column names are unique and consistent to avoid any errors in their analysis. What R function can they use to do this automatically?

 
 
 
 

18. What is the class of the object defined by the expression? x <- c(4,5,10)?

 

 
 
 
 

19. In ggplot2, an _____ is a visual property of an object in your plot.

 
 
 
 

20. A data analyst is working with the penguin’s data. They write the following code:
penguins %>%

The variable species includes three penguin species: Adelie, Chinstrap, and Gentoo. What code chunk does the analyst add to create a data frame that only includes the Gentoo species?

 
 
 
 

Frequently Asked Questions About R Language MCQs ggplot2

R Language MCQs ggplot2 Function

  • What is the class of the object defined by the expression? x <- c(4,5,10)?  
  • In R the following are all atomic data types EXCEPT:
  • For the population y<-c(1,2,3,4,5), write the R command to find the mean.
  • For the population y<-c(1,2,3,4,5), write the R command to find the median.
  • Let us have 1000 random samples of size 6 under SRSWOR using the following population (111, 150, 121, 198, 112, 136, 114, 129, 117, 115, 186, 110, 121, 115, 114) which is the R command for repeating this procedure 1500 times?
  • Which is the R command for obtaining 1000 random numbers through normal distribution with mean 0 and variance 1?
  • How sampling with and without replacement can be done using R?
  • Write the R commands for generating 700 random variables from normal distribution by using the following information: Mean = 14, SD = 3, n = 5, k = 2000.
  • Suppose you want to simulate a coin toss 20 times in R. Write the command.
  • When programming in R, what is a pipe used as an alternative for?
  • Which of the following are standards of tidy data?
  • Which summary functions can you use to preview data frames in R Language?
  • Which R function can be used to make changes to a data frame?
  • Why are tibbles a useful variation of data frames?
  • Data analysts are cleaning their data in R.
  • They want to be sure that their column names are unique and consistent to avoid any errors in their analysis. What R function can they use to do this automatically?
  • Data analysts are working with customer information from their company’s sales data. The first and last names are in separate columns, but they want to create one column with both names instead. Which of the following functions can they use?
  • A data scientist is trying to print a data frame but when you print the data frame to the console output produces too many rows and columns to be readable. What could they use instead of a data frame to make printing more readable?
  • A data analyst is working with the penguin’s data. They write the following code: penguins %>% The variable species includes three penguin species: Adelie, Chinstrap, and Gentoo. What code chunk does the analyst add to create a data frame that only includes the Gentoo species?
  • You are cleaning a data frame with improperly formatted column names. To clean the data frame you want to use the clean_names() function. Which column names will be changed using the clean_names() with default parameters?
  • In ggplot2, an ———- is a visual property of an object in your plot.

R Language MCQs 2

Computer MCQs Online Test

9 Ways to Get Help in R Language

In this article, we will discuss 9 ways to get help in R Language. R Language has a very useful and advanced help system that helps the R user to understand the R language and lets him know how programming should be done in the R language.

Get Help in R Language

To get help in R language you need to click the Help button on the toolbar of RGui (R Graphical User Interface) windows. If you have internet access on your PC you can type CRAN in Google and search for the help you need at CRAN.

Use of “?” for Help

On the other hand, if you know the name of the function, you need to type the question mark (?) followed by the name of the required function on the R command line prompt. For example to get help about “lm” function type ?lm and then press the ENTER key from the keyboard.
help(lm) or ?lm have the same search results in the R language.

help.start()

Getting General help in R write the following command at the R command prompt

help.start()

## Output
help.start()
starting httpd help server ... done
If nothing happens, you should open
‘http://127.0.0.1:13825/doc/html/index.html’ yourself
9 ways to get help in R Language

Sometimes it is difficult to remember the precise name of the function, but you know the subject on which you need help for example data input. Use the help.search function (without question mark) with your query in double quotes like this:

help.search("data input")

Press the ENTER key, you will see the names of the R functions associated with the query.  After that, you can easily use ?lm to get help in R.

Use of find(” “)

Getting help in R, find, and apropos are also useful functions. The find function tells you what package something is in: for example

find("cor") gives output that the cor in the stats package.

Use of apropos()

The apropos function returns a character vector giving the names of all objects in the search list that match your inquiry (potentially partial) i.e., this command lists all functions containing your string. For example

apropos("lm")

will give the list of all functions containing the string lm

Use of example()

example(lm) will provide an example of your required function that is in this case, an example of the function lm()

Online Help

There is a huge amount of information about R on the web. On CRAN you will find a variety of help/ manuals. There are also answers to FAQs (Frequently Asked Questions) and R News (contains interesting articles, book reviews, and news of forthcoming releases. The search facility of the site allows you to investigate the contents of the R documents, functions, and searchable mail archives.

You can search your required function or string in help manuals and archived mailing lists by using

RSiteSearch("read.csv")

Get Vignettes

vignette is an R jargon for documentation and is written in the spirit of sharing knowledge, and
assisting new users in learning the purpose and use of a package. To get some help in R try ?vignette. Vignettes are optional supplemental documentation, that’s why not all packages come with vignettes.

vignette()          # will show available vignettes
vignette("foo")     # will show specific vignette

Now you have learned about getting help in R, now you can continue with the other R tutorials. It is possible that you do not understand something discussed in the coming R tutorials. If this happens then you should use the built-in help system before going to the internet. In most cases, the help system of R Language will give you enough information about the required function that you have searched for.

Some Sources of R Help/ Manual/ Documentations

https://cran.r-project.org/manuals.html

https://cran.r-project.org/other-docs.html

https://www.r-project.org/help.html

https://cran.r-project.org/bin/windows/base/rw-FAQ.html

Weighted Least Squares In R: A Quick WLS Tutorial

Introduction to Weighted Least Squares in R

This post will discuss the implementation of Weighted Least Squares (WLS) in R. The OLS method minimizes the sum of squared residuals, while the WLS weights the square residuals. The WLS technique is used when the OLS assumption related to constant variance in the errors is violated.

The WLS technique is also known as weighted linear regression it is a generalization of ordinary least squares (OLS) and linear regression in which knowledge of the variance of observations is incorporated into the regression.

WLS in R Language

Let us perform the WLS in R.

Here we will use the mtcars dataset. You need to load this data set first using the attach() function. For example,

attach(mtcars)

Consider the following example regarding the weighted least squares in which the reciprocal of $wt$ variable is used as weights. Here two different weighted models are performed and then check the fit of the model using anova() function.

# Weighted Model 1
w_model1 <- lm(mpg ~ wt + hp, data = mtcars)

# Weighted Model 2
w_model2 <- lm(mpg ~ wt + hp, data = mtcars, weights = 1/wt)

Check/ Test The Model Fit

To check the model fit, summary statistics of the fitted model, and different diagnostic plots of the fitted model, one can use the built-in functions as,

anova(w_model1, w_model2 )
summary(w_model1)
summary(w_model2)

plot(w_model1)
plot(w_model2)

The output of the First Weighted Model is:

Call:
lm(formula = mpg ~ wt + hp, data = mtcars)

Residuals:
   Min     1Q Median     3Q    Max 
-3.941 -1.600 -0.182  1.050  5.854 

Coefficients:
            Estimate Std. Error t value Pr(>|t|)    
(Intercept) 37.22727    1.59879  23.285  < 2e-16 ***
wt          -3.87783    0.63273  -6.129 1.12e-06 ***
hp          -0.03177    0.00903  -3.519  0.00145 ** 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 2.593 on 29 degrees of freedom
Multiple R-squared:  0.8268,	Adjusted R-squared:  0.8148 
F-statistic: 69.21 on 2 and 29 DF,  p-value: 9.109e-12

The output of the Second Weighted Model is

Call:
lm(formula = mpg ~ wt + hp, data = mtcars, weights = 1/wt)

Weighted Residuals:
    Min      1Q  Median      3Q     Max 
-2.2271 -1.0538 -0.3894  0.6397  3.7627 

Coefficients:
             Estimate Std. Error t value Pr(>|t|)    
(Intercept) 39.002317   1.541462  25.302  < 2e-16 ***
wt          -4.443823   0.688300  -6.456 4.59e-07 ***
hp          -0.031460   0.009776  -3.218  0.00317 ** 
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 1.554 on 29 degrees of freedom
Multiple R-squared:  0.8389,	Adjusted R-squared:  0.8278 
F-statistic: 75.49 on 2 and 29 DF,  p-value: 3.189e-12

Graphical Representation of Models

The graphical representation of both models is:

Weighted Least Squares (Model 1)
Diagnostic Plots for WLS model: Model-1
Weighted Least Squares Model-2
Diagnostic Plots for WLS model: Model-2

FAQS Weighted Least Square in R

  1. How weighted least squares can be performed in R Lanague?
  2. How lm() function can be used to conduct a WLS in R?
  3. What are the important arguments for performing a weighted least squares model in R?

Learn about Generalized Least Squares