Supercharge your development with unmatched features:
Access a full terminal environment, run Linux commands, and manage your project’s dependencies directly within the IDE.
Browse and interact with websites directly within the IDE. Supports real-time interaction with web content without leaving the workspace.
Manage your project files and directories effortlessly within the IDE. Create, edit, rename, move, and delete files—all in one place.
Experience seamless code editing with real-time syntax highlighting, tab support, and intelligent code suggestions for a smoother development workflow.
R is a programming language and software environment primarily used for statistical computing, data analysis, and graphical representation. It is widely used by statisticians, data scientists, and researchers for its powerful data analysis capabilities and statistical models.
To start working with R, install the R software from the official website, r-project.org. Additionally, RStudio is a popular integrated development environment (IDE) for R, which you can download from rstudio.com.
# Example of checking the R version:
R --version
R is known for its intuitive and concise syntax. Commands are generally executed directly in the R console or within scripts.
# Example:
print("Hello, R!")
In R, variables are created by assigning a value using the <-
operator or the =
sign. R supports several data types like numeric, integer, character, and logical.
# Example:
age <- 25 # Numeric
name <- "Alice" # Character
is_student <- TRUE # Logical
Conditional statements in R allow you to execute code based on certain conditions using if
, else if
, and else
.
# Example:
if (age >= 18) {
print("You are an adult.")
} else {
print("You are a minor.")
}
R provides for
and while
loops for repetitive tasks. The for
loop is especially useful for iterating over elements in a vector or data structure.
# Example of a for loop:
for (i in 1:5) {
print(i)
}
# Example of a while loop:
count <- 1
while (count <= 5) {
print(count)
count <- count + 1
}
Functions in R are defined using the function
keyword. They can accept parameters and return values.
# Example:
greet <- function(name) {
paste("Hello, ", name)
}
print(greet("Alice"))
Vectors are the most basic data structure in R and are used to store a sequence of elements, such as numbers or characters.
# Example:
numbers <- c(1, 2, 3, 4, 5)
print(numbers)
Data frames are used in R to store data in a table format, similar to spreadsheets. They are used to handle and manipulate tabular data.
# Example:
data <- data.frame(Name = c("Alice", "Bob", "Charlie"),
Age = c(25, 30, 35))
print(data)
R allows you to read from and write to files, such as CSVs, using functions like read.csv()
and write.csv()
.
# Example of reading a CSV file:
data <- read.csv("example.csv")
print(data)
# Example of writing to a CSV file:
write.csv(data, "output.csv")
R has powerful plotting and visualization libraries, such as ggplot2
, which allows you to create various types of graphs and charts to visualize data.
# Example using base R plotting:
plot(x = 1:10, y = (1:10)^2, type = "b", col = "blue", xlab = "X-Axis", ylab = "Y-Axis")
# Example using ggplot2:
library(ggplot2)
ggplot(data, aes(x = Age, y = Name)) +
geom_point()