r

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

R

R

A language and environment for statistical computing and graphics.
用于统计计算和绘图的语言与环境。

When to Use

使用场景

  • Statistical Analysis
  • Data Visualization (ggplot2)
  • Bioinformatics
  • Academic research
  • 统计分析
  • 数据可视化(ggplot2)
  • 生物信息学
  • 学术研究

Quick Start

快速入门

r
print("Hello, World!")
r
print("Hello, World!")

Vector

向量

x <- c(1, 2, 3, 4, 5)
x <- c(1, 2, 3, 4, 5)

Mean

平均值

mean(x)
mean(x)

Data Frame

数据框

df <- data.frame( Name = c("Alice", "Bob"), Age = c(25, 30) )
undefined
df <- data.frame( Name = c("Alice", "Bob"), Age = c(25, 30) )
undefined

Core Concepts

核心概念

Vectorization

向量化

R operations are designed to work on entire vectors at once, avoiding explicit loops.
r
x + 1 # Adds 1 to every element in x
R的运算设计为可一次性处理整个向量,避免显式循环。
r
x + 1 # 为x中的每个元素加1

Pipe Operator
%>%

管道操作符
%>%

Used to clean code by passing output of one function as input to the next (Tidyverse).
r
data %>%
  filter(users > 100) %>%
  group_by(region) %>%
  summarize(total = sum(users))
用于简化代码,将一个函数的输出作为下一个函数的输入(Tidyverse工具集)。
r
data %>%
  filter(users > 100) %>%
  group_by(region) %>%
  summarize(total = sum(users))

Best Practices

最佳实践

Do:
  • Use the Tidyverse (dplyr, ggplot2) for modern R
  • Document functions with Roxygen2
  • Use RStudio IDE
Don't:
  • Use explicit
    for
    loops if vectorization is possible (performance)
  • Mix naming conventions (snake_case is preferred in tidyverse)
建议:
  • 使用Tidyverse(dplyr、ggplot2)进行现代R开发
  • 使用Roxygen2为函数添加文档
  • 使用RStudio IDE
不建议:
  • 在可使用向量化的情况下使用显式
    for
    循环(影响性能)
  • 混合命名规范(Tidyverse中优先使用snake_case)

References

参考资料