SyntaxStudy
Sign Up
R Getting Started with R
R Beginner 1 min read

Getting Started with R

R is a free, open-source programming language and environment designed primarily for statistical computing and data visualization. Originally created by Ross Ihaka and Robert Gentleman at the University of Auckland, R has grown into one of the most widely used tools in data science, academia, and research, backed by a rich ecosystem of packages available through CRAN (the Comprehensive R Archive Network). Unlike many general-purpose languages, R was built from the ground up with data in mind. Every operation in R is designed to work naturally on vectors, matrices, and data frames, making it exceptionally concise for statistical workflows. The language treats functions as first-class objects and supports both functional and object-oriented programming paradigms. Getting started with R involves installing R itself from cran.r-project.org and optionally RStudio as an IDE. Once set up, you can begin interactively at the console, write scripts, or author reproducible reports. Understanding the basic syntax — assignment with the `<-` operator, calling functions, and navigating the help system — lays the foundation for everything that follows.
Example
# R uses <- for assignment (= also works but <- is idiomatic)
x <- 42
name <- "Alice"
is_valid <- TRUE

# Print values to the console
print(x)
cat("Hello,", name, "\n")

# Basic arithmetic
a <- 10
b <- 3
cat("Sum:     ", a + b, "\n")
cat("Diff:    ", a - b, "\n")
cat("Product: ", a * b, "\n")
cat("Quotient:", a / b, "\n")
cat("Integer div:", a %/% b, "\n")
cat("Modulo:  ", a %% b, "\n")
cat("Power:   ", a ^ b, "\n")

# Check data types
class(x)          # "numeric"
class(name)       # "character"
class(is_valid)   # "logical"
typeof(x)         # "double"

# Accessing built-in help
# ?mean          # opens help page for mean()
# help("lm")     # opens help page for lm()

# Simple sequence and basic stats
nums <- 1:20
cat("Length:", length(nums), "\n")
cat("Mean:  ", mean(nums),   "\n")
cat("Sum:   ", sum(nums),    "\n")