Table of Contents
The argument “no” must be assigned a specific value in order for the statement “Fix in R: argument “no” is missing, with no default” to be resolved. Without a value assigned to “no”, the function or program will not be able to execute properly. It is important to provide a valid value for “no” in order to avoid any errors or missing data in the output.
Fix in R: argument “no” is missing, with no default
One error you may encounter in R is:
Error in ifelse(df$team == "B", "Boston") : argument "no" is missing, with no default
This error occurs when you use the ifelse() function in R but forget to include a third argument to specify the value that should be returned if the logical test returns false.
This tutorial shares exactly how to fix this error.
How to Reproduce the Error
Suppose we have the following data frame in R:
#create data frame df <- data.frame(team=c('B', 'B', 'B', 'B', 'C', 'C', 'C', 'D'), points=c(12, 22, 35, 34, 20, 28, 30, 18), assists=c(4, 10, 11, 12, 12, 8, 6, 10)) #view data frame df team points assists 1 B 12 4 2 B 22 10 3 B 35 11 4 B 34 12 5 C 20 12 6 C 28 8 7 C 30 6 8 D 18 10
Now suppose we attempt to use the ifelse() function to create a new column called city that contains “Boston” if the value in the team column is equal to “B”:
#attempt to create new column with team city
df$city <- ifelse(df$team=='B', 'Boston')
Error in ifelse(df$team == "B", "Boston") :
argument "no" is missing, with no defaultWe receive an error because we failed to provide a third argument in the ifelse() function that specifies the value we should return if the value in the team column is not equal to “B”.
How to Fix the Error
The way to fix this error is to simply provide a third argument in the ifelse() function that specifies the value we should return if the value in the team column is not equal to “B”.
The following syntax shows how to do so:
#create new column with team city
df$city <- ifelse(df$team=='B', 'Boston', 'Other')
#view updated data frame
df
team points assists city
1 B 12 4 Boston
2 B 22 10 Boston
3 B 35 11 Boston
4 B 34 12 Boston
5 C 20 12 Other
6 C 28 8 Other
7 C 30 6 Other
8 D 18 10 Other
Notice that we don’t receive any error this time since we provided a third argument to the ifelse() function.
In this example, the ifelse() function returns a value of “Boston” if the value in the team column is equal to “B” or a value of “Other” if the value in the team column is anything else.
Cite this article
stats writer (2024). What value should the argument “no” take in order for the statement “Fix in R: argument “no” is missing, with no default” to be resolved?. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/what-value-should-the-argument-no-take-in-order-for-the-statement-fix-in-r-argument-no-is-missing-with-no-default-to-be-resolved/
stats writer. "What value should the argument “no” take in order for the statement “Fix in R: argument “no” is missing, with no default” to be resolved?." PSYCHOLOGICAL SCALES, 26 Jun. 2024, https://scales.arabpsychology.com/stats/what-value-should-the-argument-no-take-in-order-for-the-statement-fix-in-r-argument-no-is-missing-with-no-default-to-be-resolved/.
stats writer. "What value should the argument “no” take in order for the statement “Fix in R: argument “no” is missing, with no default” to be resolved?." PSYCHOLOGICAL SCALES, 2024. https://scales.arabpsychology.com/stats/what-value-should-the-argument-no-take-in-order-for-the-statement-fix-in-r-argument-no-is-missing-with-no-default-to-be-resolved/.
stats writer (2024) 'What value should the argument “no” take in order for the statement “Fix in R: argument “no” is missing, with no default” to be resolved?', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/what-value-should-the-argument-no-take-in-order-for-the-statement-fix-in-r-argument-no-is-missing-with-no-default-to-be-resolved/.
[1] stats writer, "What value should the argument “no” take in order for the statement “Fix in R: argument “no” is missing, with no default” to be resolved?," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, June, 2024.
stats writer. What value should the argument “no” take in order for the statement “Fix in R: argument “no” is missing, with no default” to be resolved?. PSYCHOLOGICAL SCALES. 2024;vol(issue):pages.
