Your All-in-One AI-Powered Toolkit for Academic Success.

Available 24*7 on WhatsApp / Email

Unlock your academic potential

© 2024 | Zucol Services PVT LTD | All rights reserved.

Added on 2019/09/18

|1

|135

|165

Report

AI Summary

The provided R code aims to standardize the values of a given matrix by scaling each value using the formula (x - mean) / sd, where x is the value of the particular element, mean is the mean of each column, and sd is the standard deviation of the column. The code creates a 3x4 matrix, calls the function `matrix_scale` to scale the values, and then prints the scaled matrix.

Your contribution can guide someone’s learning journey. Share your
documents today.

This R code is trying to scale the matrix and transform all the values of the matrix in

standardised values. The formula for normalising the value is (x - mean)/sd

where x = value of the particular element

mean = mean of each column

sd = standard deviation of the column

#creating a matrix with 3 columns and 3 rows

matrix_1 = matrix(seq(1,12),ncol=4,nrow=3,byrow=TRUE)

matrix_1

#calling function matrix_scale

m_scl <- matrix_scale(matrix_1)

m_scl

#function to scale values of matrix

matrix_scale <- function(x) sweep(sweep(x, 2, colMeans(x)), 2, apply(x, 2, sd), '/')

standardised values. The formula for normalising the value is (x - mean)/sd

where x = value of the particular element

mean = mean of each column

sd = standard deviation of the column

#creating a matrix with 3 columns and 3 rows

matrix_1 = matrix(seq(1,12),ncol=4,nrow=3,byrow=TRUE)

matrix_1

#calling function matrix_scale

m_scl <- matrix_scale(matrix_1)

m_scl

#function to scale values of matrix

matrix_scale <- function(x) sweep(sweep(x, 2, colMeans(x)), 2, apply(x, 2, sd), '/')

1 out of 1