Analyze Data in R - Introduction to Programming Project

Hi everyone,

I was working on the project, “Day of the Race” in the Introduction to Programming in R section of the Skill Path Analyze Data with R (https://www.codecademy.com/paths/analyze-data-with-r/tracks/introduction-to-programming-in-r/modules/intro-to-programming-in-r/projects/day-of-the-race-project-R). I tried to set up the function according to the cheat sheets and trying to sort through a vector of names, but I am still not getting output from my function. So far, I have the following lines of code to a) create the function and b) call the function:

find_place <- function(runner){

place <- 1;

for(racer in race_results){

print(racer)

if(runner==racer){

  return place

} 

  place <- place + 1

  print(place)

}

return place

}


```{r}

# call and apply find_place() here:

place_of_person <- sapply("Francesca", find_place)

place_of_person
...

But I still do not get any output.  Is there something in the loop that I am not referencing?  I tried to use the HINT to correct my structure, but I still was unable to find success.

Thank you in advanced :slight_smile:

Yes, can someone answer this from Codeacademy? I think there are other users having issues with Day of the Race project as well

1 Like

The sapply() function in R works like lapply(), but it tries to interpret the output to the most fundamental data structure possible, which is either Vector or Matrix. The sapply() is a “wrapper” function for lapply().

The apply() function returns the vector or array by applying a function to the margins of the array or matrix. The lapply() function is useful for performing operations on list objects and returns the list object of the same length as the original set.