❌ subscript out of bounds
v <- c(1, 2, 3) v[4] # 存在しないインデックス(NAを返す場合とエラーになる場合がある)
✅ length(v) で長さを確認。Rのインデックスは1から始まることに注意。
❌ non-numeric argument to mathematical function
mean(c("a", "b", "c")) # 文字列に平均は求められない
✅ 数値のベクトルにのみ数学関数を適用する。class(x) でデータ型を確認する。
❌ could not find function(パッケージ未インストール)
ggplot(data, aes(x, y)) # ggplot2未インストール
✅ install.packages("ggplot2") でインストールし、library(ggplot2) で読み込む。