> # Define a vector
> vec <- c(10, 20, 30, 40, 50)
> # Subset by position
> print(vec[1]) # First element
[1] 10
> print(vec[2:4]) # Elements from position 2 to 4
[1] 20 30 40
> # Subset by negative index (exclude elements)
> print(vec[-1]) # All except the first element
[1] 20 30 40 50
> print(vec[-(2:3)]) # Exclude 2nd and 3rd elements
[1] 10 40 50
> # Subset by logical vector
> print(vec[c(TRUE, FALSE, TRUE, FALSE, TRUE)]) # Select 1st, 3rd, and 5th
[1] 10 30 50
> # Subset by condition
> print(vec[vec > 25]) # Elements greater than 25
[1] 30 40 50
> # Define a matrix
> mat <- matrix(1:9, nrow = 3, byrow = TRUE)
> # mat =
> # [,1] [,2] [,3]
> # [1,] 1 2 3
> # [2,] 4 5 6
> # [3,] 7 8 9
> # Subset by element
> mat[1, 2] # Element at 1st row, 2nd column
[1] 2
> # Subset entire row or column
> mat[2, ] # Entire 2nd row
[1] 4 5 6
> mat[, 3] # Entire 3rd column
[1] 3 6 9
> # Subset a submatrix
> mat[1:2, 2:3] # Rows 1-2, Columns 2-3
[,1] [,2]
[1,] 2 3
[2,] 5 6
> # Subset with condition
> mat[mat > 5] # All elements > 5 (returns as a vector)
[1] 7 8 6 9
> # Subset with drop = FALSE to preserve matrix structure
> mat[1, , drop = FALSE] # 1st row as a matrix
[,1] [,2] [,3]
[1,] 1 2 3
Filename: ArrayMatrix.R
# Create an array of 3x3 matrices (3 rows, 3 columns, 2 layers)
my_array <- array(1:18, dim = c(3, 3, 2))
# Print the array
print("Array of 3x3 matrices (2 layers):")
print(my_array)
# Access individual matrix (layer)
print("First 3x3 matrix:")
print(my_array[,,1])
print("Second 3x3 matrix:")
print(my_array[,,2])
[1] "Array of 3x3 matrices (2 layers):"
, , 1
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
, , 2
[,1] [,2] [,3]
[1,] 10 13 16
[2,] 11 14 17
[3,] 12 15 18
[1] "First 3x3 matrix:"
[,1] [,2] [,3]
[1,] 1 4 7
[2,] 2 5 8
[3,] 3 6 9
[1] "Second 3x3 matrix:"
[,1] [,2] [,3]
[1,] 10 13 16
[2,] 11 14 17
[3,] 12 15 18
1) Download and install R-Programming environment and install basic packages using install. packages() command in R. View Solution
2) Learn all the basics of R-Programming (Data types, Variables, Operators etc,.) View Solution
3) Write R command to
i) Illustrate summation, subtraction, multiplication, and division operations on vectors using vectors.
ii) Enumerate multiplication and division operations between matrices and vectors in R console View Solution
4) Write R command to
i) Illustrates the usage of Vector subsetting and Matrix subsetting
ii) Write a program to create an array of 3×3 matrixes with 3 rows and 3 columns. View Solution
5) Write an R program to draw i) Pie chart ii) 3D Pie Chart, iii) Bar Chart along with chart legend by considering suitable CSV file View Solution
6) Create a CSV file having Speed and Distance attributes with 1000 records. Write R program to draw
i) Box plots
ii) Histogram
iii) Line Graph
iv) Multiple line graphs
v) Scatter plot
to demonstrate the relation between the cars speed and the distance. View Solution
7) Implement different data structures in R (Vectors, Lists, Data Frames) View Solution
8) Write an R program to read a csv file and analyze the data in the file using EDA (Explorative Data Analysis) techniques. View Solution
9) Write an R program to illustrate Linear Regression and Multi linear Regression considering suitable CSV file View Solution