Convert DataFrame to Matrix in R
To convert a DataFrame to a Matrix in R using the ‘as.matrix()‘ function: Copy mat <- as.matrix(df) For example: Copy # Create a DataFrame df <- data.frame( col_a = c(1, 2, 3), col_b = c(4, 5, 6), col_c = c(7, 8, 9) ) # Convert the DataFrame to a Matrix in R mat <- as.matrix(df) … Read more