0% found this document useful (0 votes)
11 views3 pages

Ex 1

Uploaded by

nsantoshnaga
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)
11 views3 pages

Ex 1

Uploaded by

nsantoshnaga
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/ 3

Ex.No.

01 INSTALLING R AND BASIC R OPERATIONS 03/07/24

Aim
To determine various basic operations in R, such as creating, manipulating vectors, matrices and
data frames, performing basic statistical calculations, and reading data from a csv file.

Procedure
Step 1: Start
Step 2: To create sequence use function like seq() and c() to create vector
Step 3: Perform arithmetic operations and check the mode of vectors
Step 4: To reshape vectors into matrices use dim() to convert vectors into matrices
Step 5: For statistical calculation, calculate mean and median of numeric vectors
Step 6: Extend vectors by appending elements to exisiting vectors
Step 7: For creating data frame, combine vectors info data frame using data frame
Step 8: To read csv file by using read.(csv) to import data from csv
Step 9: Stop

Coding and output


1. Scatterplots with only one variable
data <- data.frame(x<-50:1)
# Draw Plot with the n row function
ggplot(data, aes(x = 1:nrow(data), y = x) ) +geom_point()

2. Bar plot with only one variable


data <- data.frame(x<-50:1)
# Draw Plot with the nrow function
ggplot(data, aes(x = 1:nrow(data), y = x)) + geom_bar(stat="identity")

3. Plots from data frame


x <- c(1, 2, 3, 4, 5)
y <- c(10, 20, 30, 40, 50)
df <- data.frame(x, y)
ggplot(data = df) + geom_point(aes(x = x, y = y))

4. Simple scatter plot


# Create sample data frame
x <- c(1, 2, 3, 4, 5)
y <- c(10, 20, 30, 40, 50)
df <- data.frame(x, y)

# Plot the data frame using ggplot2


ggplot(data = df) + geom_point(aes(x = x, y = y), size = 4, color = "blue") + ggtitle("Simple Scatter
Plot") + xlab("X Variable") + ylab("Y Variable")

5. Importing ggplot2
# Importing ggplot2
library(ggplot2)
# Creating a data frame
data_frame1 = data.frame(x= c(2,4,3,1),y = c(3,1,6,8))
# Plotting the data
ggplot(data_frame1,aes(x = x , y =y)) + geom_point()+ theme(panel.background = element_rect(fill
= 'green', color = 'blue'))

Result
Thus the above code is executed successfully and also created, manipulated vectors
matrices, data frames from csv files.

You might also like