Back to Practice
#0144

Add a Derived Column in R

EasyR15 min10 XP

Problem

Given a data frame with price and quantity, add revenue = price * quantity.

Why This Matters

Feature creation in R often starts with simple column arithmetic.

Examples

Example 1
Inputprice 10 qty 3; price 20 qty 2
Outputrevenue 30 and 40

R multiplies the two columns element-wise.

Constraints

  • Return the exact requested structure.
  • Handle normal edge cases cleanly.
  • Prefer readable code over clever shortcuts.
CodeR
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputprice 10 qty 3; price 20 qty 2
Expectedrevenue 30 and 40

R multiplies the two columns element-wise.

Hidden Test Categories
decimal pricezero quantitynew column name