R vs Python — Picking the Right Tool
The Riverside community garden keeps a harvest log: five plots, the crop in each, how many kilograms it gave, and whether it was watered. The volunteers want averages, comparisons and a chart for the newsletter. Both R and Python could do this job, so before you learn R it helps to know what it was built around and where it feels at home.
The rule
R was built for data first; Python was built for everything, then data.
R began in the early 1990s at the University of Auckland, where Ross Ihaka and Robert Gentleman wrote a free language modelled on S, a statistics language from Bell Labs. It was designed by statisticians for statisticians, and it shows:
- Every value is a vector. A single number is just a vector of length one, so arithmetic runs on whole columns of data at once.
- Statistics are built in.
mean(),median(),sd(),summary(),t.test()andlm()(linear models) come with R itself, with no imports. - Plotting is built in, and packages such as ggplot2 make publication-quality charts.
- Counting starts at 1, the way people count, not at 0.
Here is the garden's harvest, in kilograms:
kg <- c(12.5, 8, 15, 3.5, 6) # plots A to E
mean(kg) # 9
kg * 1000 # 12500 8000 15000 3500 6000, every value at once
kg[1] # 12.5, the first plotc() combines values into a vector and <- stores it under a name. In plain Python, multiplying a list by 1000 would repeat the list 1000 times; you need a loop or the NumPy library to get what R does by default.
Python is a general-purpose language. It builds websites, automates chores and runs production systems, and it reaches data work through libraries such as pandas and NumPy. Machine-learning teams lean towards Python; statistics, research and reporting teams lean towards R. Many teams use both.
The shortcut
Ask one question about the job: "Is the main work analysing, modelling or charting data?" If yes, R is on its home ground. If the main work is building software around the data (an app, a service, an automation), Python usually fits better.
A harvest summary with a chart
Averages per crop and a bar chart for the newsletter. The main work is analysis and charting, so R fits.
The trap is treating this as a rivalry. You are picking a tool for a task, and plenty of analysts write R in the morning and Python in the afternoon.
Drills
Answer fast — trust the rule.
With kg <- c(12.5, 8, 15, 3.5, 6), what is kg[1]?
What does kg * 2 return?
In R, what is the value 5 on its own?
Which job is most clearly R's home ground?
Remember
- R was built for data first; Python was built for everything, then data.
- Shortcut: if the main work is analysing, modelling or charting data, start in R.
- Trap: R counts from 1 and works on whole vectors at once. Do not bring 0-based, one-value-at-a-time habits with you.
