My data is in a 1 column x 40000 row data frame. I would like to make it a 200 column x 200 row data frame. When I was using all numeric values, I used the code below to transform my vector into a matrix.
spematrix=data.matrix(spe)
matrix = matrix(spematrix, nrow = 200, ncol=200)
I cannot use this now though because my data contains non-numeric values (numbers separated by commas).
I am new to R and would appreciate any help.
Sounds like you already know what to do. You can scrub your data with gsub to remove the , characters:
spe <- gsub(",","",spe[,1]) # returns a character vector
spe <- as.numeric(spe) # convert to numeric
Then,
library(Matrix)
spematrix <- data.matrix(spe)
matrix = Matrix(spematrix, nrow = 200, ncol=200)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With