Using this data, your example works for me:
data <- matrix(sample(1:1000,17*6), ncol=17,nrow=6) for(i in 1:nrow(data)){ x <- data[i, ] data[i, ] <- scale(x, min(x), max(x)-min(x)) }
Here is another option using a scale, without a loop. You just need to provide the scale and center the same columns as your matrix.
maxs <- apply(data, 2, max) mins <- apply(data, 2, min) scale(data, center = mins, scale = maxs - mins)
EDIT how to access the result.
The scale returns a matrix with 2 attributes. To get the data.frame file, you just need to force the scaling result to data.frame.
dat.scale <- scale(data, center = mins, scale = maxs - mins) dat.sacle <- as.data.frame(dat.scale)
source share