R for Data Analysis by Mike McGrath

R for Data Analysis by Mike McGrath

Author:Mike McGrath
Language: eng
Format: epub, azw3
Publisher: In Easy Steps
Published: 2018-02-03T05:00:00+00:00


A matrix in R resembles a multi-dimensional array structure found in other programming languages.

Begin an R Script by creating a vector containing a sequence of 32 integer values

data <- seq( 1:32 )

FirstMatrix.R

Next, create a matrix that stores the vector values in tabular format, then output the matrix to see the cells

table <- matrix( data, nrow=4, ncol=8 )

print( table )

Now, confirm the type of structure storing the values

cat( “\nVector?:”, is.vector( table ) ,

“\tMatrix?:”, is.matrix( table ) )

Retrieve a cell value, then assign a new value to that cell

cat( “\n\nCell 4,5 Contains:”, table[ 4, 5 ] )

table[ 4, 5 ] <- 10

Finally, search all cells for a specific value, and identify the location of cells that do contain that value

cell <- which( table == 10, arr.ind=TRUE )

cat( “\n\nValue 10 Search:\n” )

print( cell )

Run the code to see the cell values and search result



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.