0% found this document useful (0 votes)
3 views16 pages

R New

R is a programming language focused on statistical computing and data visualization, popular among data scientists. The document provides a step-by-step guide for installing R on a system, including downloading, installation options, and customization. It also includes example programs demonstrating basic R programming concepts such as arithmetic operations, conditional statements, loops, and data structures.

Uploaded by

shaidamomin5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views16 pages

R New

R is a programming language focused on statistical computing and data visualization, popular among data scientists. The document provides a step-by-step guide for installing R on a system, including downloading, installation options, and customization. It also includes example programs demonstrating basic R programming concepts such as arithmetic operations, conditional statements, loops, and data structures.

Uploaded by

shaidamomin5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 16

R language

R PROGRAMMING LANGUAGE

R is a domain-specific programming language designed primarily for statistical


computing and data visualization. Developed in the early 1990s by Ross Ihaka and Robert
Gentleman, R excels in data analysis, machine learning, and graphical representation, making it
a favourite among statisticians and data scientists.

It features extensive packages for various statistical techniques and offers strong data
visualization capabilities through tools like ggplot2. As an open-source language, R is
accessible on multiple platforms and supports integration with other programming languages.

STEP BY STEP GUIDE TO INSTALL R ON YOUR SYSTEM

 Download the installable file from the following link:

o https://cran.r-project.org/bin/windows/base/

 Click on the R 3.2.2.exe file. The 3.2.2 is the version number of the file. The versions
can be updated as per the latest releases.

1
R language

 The Set Up will request permission to be installed on the system click yes to proceed.

2
R language

 Select the Preferred language from the dropdown to begin an installation in that
preferred language.

 Click next to proceed with the installation.

3
R language

4
R language

 Choose the path where you wish to install R by clicking on browse and changing the
workspace locations. Click next to proceed with the default installation. The minimum
space requirements are mentioned at the bottom of the dialog box. Please check you
have required amount of free space in your drive.

 Choose the type of installation you require. By defaults R installs both the 32 and 64
bits versions on your system. If your system is a 32 bits system you will be requiring a
32 bits installation if the system is a 64 bits system it will be requiring 64 bit
installation. Do not uncheck the Core Files and Message Translations. Please make note
of the space requirement of the installation.

5
R language

 To customize the startup options for R choose option and customize. To proceed with a
vanilla installation use Next.

6
R language

 To generate program shortcuts and naming those as per your requirement specify the
necessary customizations. To proceed with the default installation hit next.

7
R language

 Click on the next button to begin your installation.

 After the installation has completed you will see the final screen. Click finish to
complete the installation.

8
R language

 Open Start Menu and you will find R in the available set of Programs.

 Click on the R icon in the menu settings to open R.


9
R language

 You are all set to use R to begin programming.

Example programs R programming

1. Basic Arithmetic Operations


Code:
a <- 10
b <- 5
sum_result <- a + b
diff_result <- a - b
prod_result <- a * b
div_result <- a / b

10
R language

print(sum_result)
print(diff_result)
print(prod_result)
print(div_result)

Output:
csharp
Copy
[1] 15
[1] 5
[1] 50
[1] 2

2. Simple Conditional Statement


Code:
R
Copy
x <- 15
if (x > 10) {
print("x is greater than 10")
} else {
print("x is less than or equal to 10")
}
Output:
csharp
[1] "x is greater than 10"

3. Loop Example (For Loop)


11
R language

Code:
R
Copy
for (i in 1:5) {
print(i)
}

Output:
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5

4. Create and Print a Vector


Code:
my_vector <- c(2, 4, 6, 8, 10)
print(my_vector)
Output:

[1] 2 4 6 8 10

5. Access Elements of a Vector


Code:

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


print(my_vector[3])
12
R language

Output:
csharp
Copy
[1] 3
6. Simple Function to Add Two Numbers
Code:
add_numbers <- function(a, b)
{
return(a + b)
}
result <- add_numbers(5, 3)
print(result)
Output:
[1] 8

7. Create a Matrix
Code:
my_matrix <- matrix(1:6, nrow = 2, ncol = 3)
print(my_matrix)
Output:

[,1] [,2] [,3]


[1,] 1 3 5
[2,] 2 4 6

8. Access Element in a Matrix


Code

13
R language

element <- my_matrix[2, 3]


print(element)
Output:
[1] 6

9. Data Frame Example


Code:
my_data <- data.frame(Name = c("Alice", "Bob", "Charlie"), Age = c(25, 30, 35))
print(my_data)
Output:
Name Age
1 Alice 25
2 Bob 30
3 Charlie 35

10. Sorting a Vector


Code
my_vector <- c(5, 2, 8, 1, 9)
sorted_vector <- sort(my_vector)
print(sorted_vector)
Output:
[1] 1 2 5 8 9

here are the simple R programs with outputs that will help you understand basic R
programming concepts like vectors, loops, functions, matrices, and data frames. Let me
know if you'd like more examples or explanations!

14
R language

15
R language

16

You might also like