Home Python C Language C ++ HTML 5 CSS Javascript Java Kotlin SQL DJango Bootstrap React.js R C# PHP ASP.Net Numpy Dart Pandas Digital Marketing

R Introduction


Absolutely! Here's a beginner-friendly introduction to R with examples:

What is R?

R is a programming language and environment for statistical computing and graphics. It's widely used by statisticians, data analysts, and researchers to analyze data and create visualizations.

Example 1: Basic Arithmetic Operations

Example

# Addition
3 + 5
# Subtraction
10 - 2
# Multiplication
4 * 6
# Division
20 / 5

Example 2: Variables

In R, you can store values in variables.

Example

# Assigning values to variables
x <- 10
y <- 5
# Using variables in operations
z <- x + y
z # This will print the value of z, which is 15

Example 3: Vectors

Vectors are sequences of elements of the same data type.

Example

# Creating a numeric vector
numbers <- c(1, 2, 3, 4, 5)
# Creating a character vector
fruits <- c("apple", "banana", "orange")

Example 4: Functions

R comes with many built-in functions.

Example

# Square root function
sqrt(25) # This will return the square root of 25, which is 5
# Mean function
mean(c(1, 2, 3, 4, 5)) # This will return the mean of the vector, which is 3

Example 5: Data Frames

Data frames are used to store tabular data.

Example

# Creating a data frame
df <- data.frame(
Name = c("Alice", "Bob", "Charlie"),
Age = c(25, 30, 35),
Sex = c("Female", "Male", "Male")
)
# Viewing the data frame
df

These examples cover some basic concepts in R to get you started. As you continue learning, you can explore more advanced topics such as data manipulation, plotting, statistical analysis, and machine learning. R has a vast community and plenty of resources available online for further learning.


Advertisement





Q3 Schools : India


Online Complier

HTML 5

Python

java

C++

C

JavaScript

Website Development

HTML

CSS

JavaScript

Python

SQL

Campus Learning

C

C#

java