Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Challenge: Inline Functions with apply | Anonymous Functions in R
Functions and Functional Programming in R

bookChallenge: Inline Functions with apply

Tâche

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

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 4
single

single

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

close

bookChallenge: Inline Functions with apply

Glissez pour afficher le menu

Tâche

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 desktopPassez à un bureau pour une pratique réelleContinuez d'où vous êtes en utilisant l'une des options ci-dessous
Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 4
single

single

some-alt