Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: Inline Functions with apply | Anonymous Functions in R
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Functions and Functional Programming in R

bookChallenge: Inline Functions with apply

Task

Swipe to start coding

Use your understanding of anonymous functions and the apply family to classify each element in a numeric vector as "positive", "negative", or "zero".

  • Create function determine_sign that take a list.
  • Use sapply with an anonymous function to process each element of the input vector.
  • The function must return a character vector of the same length as the input, with each element classified as "positive", "negative", or "zero".

The result for (3, -2, 0, 7, -5) should look like:

"positive" "negative" "zero" "positive" "negative"

Solution

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 4
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Can you explain this in simpler terms?

What are the main benefits or drawbacks?

Can you give me a real-world example?

close

bookChallenge: Inline Functions with apply

Swipe to show menu

Task

Swipe to start coding

Use your understanding of anonymous functions and the apply family to classify each element in a numeric vector as "positive", "negative", or "zero".

  • Create function determine_sign that take a list.
  • Use sapply with an anonymous function to process each element of the input vector.
  • The function must return a character vector of the same length as the input, with each element classified as "positive", "negative", or "zero".

The result for (3, -2, 0, 7, -5) should look like:

"positive" "negative" "zero" "positive" "negative"

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 2. ChapterΒ 4
single

single

some-alt