# R function
hello.person <- function(firstName, lastName = "Ansari")
{
print(sprintf("Hello %s %s", firstName, lastName))
}
# different way of function calling
hello.person("Rumman")
hello.person(firstName = "Rumman")
hello.person(firstName = "Ansari", "Azmi")
# this function calling will not work
hello.person(lastName = "Rumman")
> hello.person("Rumman")
[1] "Hello Rumman Ansari"
>
> hello.person(firstName = "Rumman")
[1] "Hello Rumman Ansari"
>
> hello.person(firstName = "Ansari", "Azmi")
[1] "Hello Ansari Azmi"
> # this function calling will not work
> hello.person(lastName = "Rumman")
Error in sprintf("Hello %s %s", firstName, lastName) :
argument "firstName" is missing, with no default
hello.person(lastName = "Rumman") First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.
Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.