Translation Traps
AI translation is useful, but it often hides small language differences. These are the traps to check first.
Trap 1: Indexing
R starts counting at 1. Python starts counting at 0.
Python slices are end-exclusive:
This returns the first two values, not the first three.
Walk through it position by position. Python labels the items position 0 (10), position 1 (20), and position 2 (30). The slice values[0:2] starts at position 0 and stops just before position 2 — that is what “end exclusive” means: the end position itself is left out. So you get 10 and 20, but not 30. The matching R code is values[1:2], because R starts counting at 1 and includes both ends. This off-by-one difference is one of the most common AI translation bugs, so always count a small example by hand.
Trap 2: Indentation
R uses braces to mark code blocks. Python uses indentation.
If Python indentation is inconsistent, the code may fail or run with a different meaning.
Trap 3: Assignment vs. Comparison
| Meaning | R | Python |
|---|---|---|
| assign a value | x <- 10 |
x = 10 |
| compare values | x == 10 |
x == 10 |
| missing/null check | is.na(x) |
pd.isna(x) or x is None |
Trap 4: Missing Values
R and Python both have missing values, but they are handled by different functions. Always check missingness before comparing summaries.
Audit Habit
When a translated result differs, check indexing, indentation, assignment/comparison, missingness handling, and grouping variables before assuming one language is “wrong.”