Menu
Coddy logo textTech

Recap - Data Pipeline

Part of the Logic & Flow section of Coddy's R journey. Lesson 36 of 64.

challenge icon

Challenge

Hard

Complete sales_report(records). Each record is item:quantity:price. Build the report in three stages:

  1. Parse the records into a list with lapply().
  2. Keep the records with a quantity above 0 with Filter().
  3. Compute each kept line total (quantity times price) with sapply() and the grand total with Reduce().

Return one line per kept record, tea: 8.00, then Total: with the grand total and Skipped: with the number of records that had quantity 0. Show money with two decimals.

The supplied code reads the records as a comma-separated line and prints each returned line.

Try it yourself

sales_report <- function(records) {
  # Write your code here
  character(0)
}

# Supplied input/output code: keep it as it is
input <- suppressWarnings(readLines(file("stdin")))
cat(sales_report(strsplit(input[1], ",")[[1]]), sep = "\n")

All lessons in Logic & Flow

Practice on your own: Online R compiler