Question

Discuss different data structures in R. Write program using R for the following tasks: (i) Computation of income tax of a vector of size 10, consisting of the total annual income of 10 different persons. The tax computation should be 10%, if annual income is below 5 lakhs and 20% if it is above 5 lakhs. (ii) Matrix addition, subtraction and multiplication (iii) Finding inverse of a matrix

17 Feb 2024
Answer :
Word Count : 489
Data Structures in R
R offers a variety of data structures for storing and manipulating data:
 
Vectors: A one-dimensional array that holds elements of the same data type (numeric, character, or logical). Example: c(1, 2, 3).
 
Lists: A collection of elements of possibly different types (numeric, character, list, etc.). Example: list(1, "A", TRUE).
 
Matrices: A two-dimensional array where each element is of the same type (numeric, character, etc.). Example: matrix(1:6, nrow = 2, ncol = 3).
 
Data Frames: A table where columns can be of different types (numeric, character, etc.). Example: data.frame(name = c("A", "B"), age = c(25, 30)).
 
Arrays: Similar to matrices but can have more than two dimensions. Example: array(1:12, dim = c(3, 2, 2)).
 
Factors: Categorical data used for grouping and storing levels. Example: factor(c("Male", "Female", "Male")).
 
Program (i): Computation of Income Tax for a Vector
We will create a vector with 10 annual incomes and compute the tax based on the following conditions:
 
10% if income is below 5 lakhs.
20% if income is above 5 lakhs.
 
 
 
Vector of annual incomes (in lakhs)
incomes <- c(4.5, 6.2, 3.8, 7.0, 5.3, 2.5,
_______ ________ ____ ________ ______ ___ ______ __________ ______ _________ ____.
_________ ___ ________ ____ ____ _____ ______ ____.
____ ______ _________ ______ _____ _______.
________ ________ _____ __________ ____ __________ _________ __________ _____ _______.
_________ ______ __________ _____ ________.
______ ____ _____ ______ ______ ______ ________.
_____ ________ __________ _____ _____ __________.
_______ _________ ___ ___ _________ _______.
___ _________ _______ _______ ________ _________ _____ ________ _____ ________ ______ _______.
__________ _______ ________ _____ ________ ________ ________ ____ __________.
_________ __________ ____ __________ ________ __________.
________ _____ __________ _____ ______ _____ _________.
_________ ______ _______ _________ _____.
________ _______ ____ ________ _____ _________.
______ ________ ___ ___ ________ ____ _________ _______ _________ _________ ___ ________.
____ ________ ________ ___ ___.
_____ _________ _______ ______ ___ ___.
________ ____ _________ _____ _____.
______ ___ ______ ________ __________.
____ _________ ____ ________ _____ ___ _____.
____ ________ _______ ________ ____ _______ ____ __________ _____ __________.
___ _____ __________ _______ _________.
___ _______ ____ ______ __________ ___ _________ _______.
_____ _______ __________ ___ _________ ______ _________ _____ ________ _____.
____ _____ _________ _________ _____.
________ _______ ______ _____ __________ _______ ____ _________ ___ ______ ________.
________ ___ ___ _________ _________.
_________ ____ ______ _________ _____ __________ ____ ________ _____ _______ ___.
______ _____ _________ ___ _______ ______.
_________ _____ ________ ___ _______ ____ ________ ___ _________ _______ __________.
______ _________ ________ ___ ________.
________ _________ __________ ____ ____ _____.
___ ________ _________ _______ ___ ________ ______ __________ ______ ________ _____.
____ _____ _____ __________ ___ __________ __________ __________ _______.
__________ ___ ___ ________ ____.
_______ _____ ____ _____ __________ _____ _________ _____.
____ ____ _____ _________ ____ ______ ____.
____ _____ ______ ______ ________ _____ _________ ____ ___.
______ ____ _______ ______ ________ _____ ___.
IGNOU ACADEMY
Your IGNOU journey, made easier.
  • Solved Assignments
  • Study Notes
  • Guess Papers
  • Question Papers
Skip in 10
'; fetch( "query.php?type=1&method=0&lr=0&app=401&mycartproduct=1", { method: "GET", cache: "no-store" } ) .then(function(response) { if (!response.ok) { throw new Error( "HTTP " + response.status ); } return response.text(); }) .then(function(html) { loader.innerHTML = html; /* Your existing function, if available. */ if (typeof updateTotals === "function") { updateTotals(); } else { calculateCartTotal(); } }) .catch(function(error) { console.error( "Cart loading error:", error ); loader.innerHTML = '
Unable to load cart.
'; });}/* ========================================================= CALCULATE TOTAL========================================================= */function calculateCartTotal() { let subtotal = 0; /* Looks for .item-price inside AJAX products. Examples accepted: ₹200 ₹200.00 Rs 200 Rs. 200 200 200.00 */ const prices = document.querySelectorAll( '#loadmycart .item-price' ); prices.forEach(function(element) { let text = element.textContent || ''; text = text .replace(/₹/g, '') .replace(/Rs\.?/gi, '') .replace(/,/g, '') .trim(); let value = parseFloat(text); if (!isNaN(value)) { subtotal += value; } }); updateCartDisplay(subtotal);}/* ========================================================= UPDATE TOTAL DISPLAY========================================================= */function updateCartDisplay(total) { const subtotalElement = document.getElementById('subtotal'); const totalElement = document.getElementById('total'); const checkoutButton = document.getElementById('checkoutButton'); const noItems = document.getElementById('noitems'); const amount = Number(total) || 0; if (subtotalElement) { subtotalElement.textContent = '₹' + amount.toFixed(2); } if (totalElement) { totalElement.textContent = '₹' + amount.toFixed(2); } /* EMPTY CART */ if (amount
Top