Search⌘ K

Challenge 1: Append Hearts

Explore how to write a function in R that transforms numeric vectors into repeated heart strings. This lesson helps you practice vector manipulation and string replication in R programming, building foundational skills for data analysis challenges.

Problem Statement

Implement the function hearts() that takes a vector as input and returns a vector whose each element is a string “<3” replicated the number of times mentioned in the corresponding input vector.

Input

A testVariable containing a vector of numbers.

Output

A vector of strings.

Sample Input

testVariable <- c(5, 2)

Sample Output

"<3<3<3<3<3", "<3<3"

Test Yourself

Write your code in the given area. If you get stuck, you can look at the solution.

R
hearts <- function(testVariable)
{
# Write your code here
}

In the next lesson, we have a solution review for this challenge.