0% found this document useful (0 votes)
1 views1 page

Vector Algebra

vector algebra

Uploaded by

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

Vector Algebra

vector algebra

Uploaded by

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

Powered by AI

Copilot

Certainly! In R programming, linear algebra operations on vectors are fundamental for data manipulation,
modeling, and analysis. Let’s explore some common operations:

1. Creating Vectors:

Vectors can be created using the c() function or other methods like seq() or : (colon).
Example:
# Creating vectors
x <- c(1, 2, 3, 4, 5)
y <- seq(1, 10, length.out = 5)
z <- 5:10

2. Accessing Vector Elements:

Use the subscript operator [] to access specific elements.


Example:
# Accessing elements
second_element <- x[2]
subset_elements <- y[c(4, 1)]
logical_subset <- z[z > 3]

3. Modifying Vectors:

You can modify vector elements using indexing.


Example:
# Modifying elements
x[3] <- 11
x[x > 9] <- 0

4. Arithmetic Operations:

Perform element-wise arithmetic operations between vectors.


Example:
# Arithmetic operations
addition <- x + y
subtraction <- x - y
multiplication <- x * y
division <- x / y

5. Sorting Vectors:

Use the sort() function to sort vectors in ascending order.


Example:
# Sorting
sorted_x <- sort(x)

Remember, mastering these operations is crucial for effective data analysis and modeling in R! If you have
more questions or need further examples, feel free to ask. 😊

You might also like