This is sample of my matrix and my code. I want to rescale my dataframe so that the each row has magnitude 1. I'm new to r and in the tutorial the instructor said "divide each element of a row by the magnitude of the row." however I'm not sure how can I get the magnitude of the row or rescale the dataframe. So I tried to use apply() however after testing my rescale using sqrt(sum(sc_mydata[r,]^2)) I didn't get 1 and I the result of x should be 1
#dataframe
myData <- myData[1:12]
#transpose
x <- t(myData)
#rescale the data
sc_mydata = apply(x[-1,], 1, scale)
#test rescale
for (r in 1:nrow(sc_mydata)) {
#test rescale if this is equal to 1 then the rescaling worked
x <- sqrt(sum(sc_mydata[r,]^2))
}