R Online Compiler

Run R code online with ggplot2, dplyr, tidyr and data.table installed. See the console output and your plots side by side. Free, no setup.

3 การดำเนินการทั้งหมด (3 ในเดือนนี้)
ผลลัพธ์

ฝึก Python ด้วยโจทย์เขียนโค้ด

แก้โจทย์จริงใน editor นี้: รันทดสอบตัวอย่าง ส่งคำตอบ และรับรีวิวโค้ดจาก AI

โจทย์ Python ทั้งหมด
ง่าย

Rectangle Perimeter

Compute the perimeter of a rectangle from its sides.

คุณจะได้เรียนรู้ เลขคณิตค่าที่คืนกลับ
ผู้เริ่มต้นLearning-pathVariables
ง่าย

Distance Between Points

Compute the straight-line distance between two points.

คุณจะได้เรียนรู้ ทฤษฎีบทพีทาโกรัสรากที่สอง
ผู้เริ่มต้นฟังก์ชันLearning-pathคณิตศาสตร์
ง่าย

Average of Three

Average three whole numbers.

คุณจะได้เรียนรู้ เลขคณิตการหาร
ผู้เริ่มต้นLearning-pathVariables
ง่าย

ผลคูณจุดของเวกเตอร์สองตัว

คูณเวกเตอร์สองตัวทีละสมาชิกแล้วรวมผลลัพธ์ ซึ่งเป็นการคำนวณหลักของทุกนิวรอน

คุณจะได้เรียนรู้ เวกเตอร์ผลคูณจุด
โครงข่ายประสาทเทียมaiการเรียนรู้ของเครื่อง
ง่าย

Days in a Month

Return how many days a month has, including leap years.

คุณจะได้เรียนรู้ กฎของปฏิทินฟังก์ชันช่วย
ผู้เริ่มต้นเงื่อนไขฟังก์ชันLearning-path
ง่าย

ตรวจสอบจำนวนเฉพาะ

ตัดสินว่าตัวเลขเป็นจำนวนเฉพาะหรือไม่

คุณจะได้เรียนรู้ การหารลงตัวปรับลูปให้เร็วขึ้น
ผู้เริ่มต้นลูปตัวเลขนักเรียนมือใหม่
ง่าย

Celsius to Fahrenheit

Convert a temperature from Celsius to Fahrenheit.

คุณจะได้เรียนรู้ สูตรลำดับความสำคัญของตัวดำเนินการ
ผู้เริ่มต้นLearning-pathVariables
ง่าย

สามเหลี่ยมตัวเลข

สร้างสามเหลี่ยมที่มีตัวเลขเพิ่มขึ้นในแต่ละแถว

คุณจะได้เรียนรู้ แถวที่ยาวขึ้นตัวนับข้ามแถว
ผู้เริ่มต้นLearning-pathลูปซ้อนแพทเทิร์น
ง่าย

Min and Max Together

Find the smallest and largest value in one pass.

คุณจะได้เรียนรู้ ไล่รอบเดียวคืนหลายค่า
Arraysผู้เริ่มต้นฟังก์ชันLearning-path
ง่าย

นับคู่ที่มีผลรวมเท่ากับค่าที่กำหนด

นับจำนวนคู่ของตำแหน่งที่ค่ารวมกันได้เท่ากับเป้าหมายที่กำหนด

คุณจะได้เรียนรู้ คู่ดัชนีหลีกเลี่ยงการนับซ้ำ
Arraysผู้เริ่มต้นLearning-pathลูปซ้อน
ง่าย

Absolute Value Without abs

Compute an absolute value with a condition.

คุณจะได้เรียนรู้ การกลับเครื่องหมายไม่ใช้ฟังก์ชันในตัว
ผู้เริ่มต้นเงื่อนไขLearning-path
ง่าย

Largest of Three

Pick the largest of three numbers without a built-in max.

คุณจะได้เรียนรู้ การเปรียบเทียบรวมเงื่อนไข
ผู้เริ่มต้นเงื่อนไขLearning-path

🧩 About This R Online Compiler

The CodeUtility R Online Compiler lets you write and run R code in your browser - no R installation, RStudio or package setup needed. Your code runs with R 4.4 in an isolated sandbox, and the console output appears next to the editor.

Popular packages are already installed: tidyverse (dplyr, tidyr, readr, purrr, stringr), ggplot2, data.table, lubridate, janitor, zoo, patchwork, viridis, scales, and modelling packages such as caret, randomForest, rpart, e1071, glmnet and cluster. Load them with library() as usual.

Charts work out of the box: every plot your code draws (base R or ggplot2) is shown as an image under the output, and you can open it full size or download it as a PNG.

It is a quick way for students to practise R, for analysts to test a snippet before running it on real data, and for teachers to share a working example with a class.

มากกว่าเครื่องมือรันโค้ด

ใช้ตัวแก้ไขหลายไฟล์ เทอร์มินัลประมวลผลแบบแยกส่วน ไลบรารีเฉพาะรันไทม์ พื้นที่ทำงานถาวร การแชร์ และการทำงานร่วมกันแบบเรียลไทม์ได้จากตัวประมวลผลเดียวกัน

วิธีใช้ตัวประมวลผลนี้

เลือกรันไทม์ เปิดหรือสร้างไฟล์ เขียนโค้ด แล้วเลือกเรียกใช้ ผลลัพธ์จะแสดงในเทอร์มินัล ส่วนผู้ใช้ที่ลงชื่อเข้าใช้สามารถเก็บไฟล์ในพื้นที่ทำงาน ติดตั้งไลบรารี และทำงานร่วมกันผ่านการแชร์ได้

  1. เลือกเวอร์ชันแล้วแก้ไขไฟล์ปัจจุบัน หรือเปิดไฟล์อื่นในพื้นที่ทำงาน
  2. เรียกใช้โค้ด ป้อนข้อมูลในเทอร์มินัลเมื่อระบบร้องขอ และตรวจสอบประวัติการเรียกใช้ที่บันทึกไว้
  3. ใช้ไลบรารี เครื่องมือพื้นที่ทำงาน การแชร์ และแชท เมื่องานของคุณต้องใช้โค้ดมากกว่าหนึ่งส่วน

💡 R Basics Guide for Beginners

1. Variables and Assignment

R uses <- to assign a value (= works too). Names are case-sensitive.

name <- "Alice"
age <- 30
is_student <- FALSE
cat(name, "is", age, "years old\n")

2. Vectors

A vector holds values of one type. Most operations work on the whole vector at once.

scores <- c(72, 88, 95, 64)
mean(scores)        # 79.75
scores * 2          # every value doubled
scores[scores > 70] # 72 88 95
length(scores)

3. Conditionals

Use if / else for one value and ifelse() for a whole vector.

x <- 7
if (x %% 2 == 0) {
  print("even")
} else {
  print("odd")
}

ifelse(scores >= 70, "pass", "fail")

4. Loops

for walks over a vector; while repeats while a condition holds.

for (i in 1:3) {
  cat("Step", i, "\n")
}

n <- 1
while (n < 100) n <- n * 2
print(n)  # 128

5. Functions

Functions are values; the last expression is returned. Arguments can have defaults.

area <- function(width, height = width) {
  width * height
}
area(3, 4)  # 12
area(5)     # 25

6. Lists

A list can hold values of different types, with names.

person <- list(name = "Bao", age = 21, langs = c("R", "SQL"))
person$name
person[["langs"]][2]  # "SQL"
str(person)

7. Data Frames

A data frame is a table: each column is a vector of the same length.

df <- data.frame(
  city = c("Hanoi", "Paris", "Lima"),
  temp = c(31, 18, 22)
)
df[df$temp > 20, ]
summary(df$temp)

8. Apply Functions

sapply() and lapply() run a function on every element, without writing a loop.

words <- c("apple", "kiwi", "banana")
sapply(words, nchar)
lapply(1:3, function(n) n^2)

9. dplyr Pipelines

The pipe (|> or %>%) passes a result to the next step.

library(dplyr)
mtcars |>
  group_by(cyl) |>
  summarise(avg_mpg = mean(mpg), cars = n()) |>
  arrange(desc(avg_mpg))

10. Plots with ggplot2

Map columns to axes and colours, then add layers. The chart appears under the output.

library(ggplot2)
ggplot(mtcars, aes(wt, mpg, color = factor(cyl))) +
  geom_point(size = 3) +
  labs(title = "Weight vs. fuel use", color = "Cylinders")

11. Strings

paste() joins text, sprintf() formats it, and stringr has friendly helpers.

paste("Hello", "R", sep = ", ")
sprintf("%.1f%% done", 42.567)
toupper("data")
library(stringr)
str_detect(c("cat", "dog"), "a")

12. Handling Errors

tryCatch() runs code and handles an error or a warning instead of stopping.

result <- tryCatch(
  log(-1),
  warning = function(w) {
    message("Warning: ", conditionMessage(w))
    NA
  }
)
print(result)