[R] scaling variables consecutively and independently

David Winsemius dwinsemius at comcast.net
Mon Aug 3 22:29:26 CEST 2015


On Aug 3, 2015, at 1:06 PM, Ram09 wrote:

> Yes, I've been using the scale function but I don't know how to write a line
> of code that will scale the scores in each variable independently of each
> other instead of as a whole.

You do not appear to be reading the help page for `scale`.

>  In other words, how can I get the scale
> function to standardize all the scores in one variable (column) then move on
> to the the next, so on and so forth for the whole dataset without having to
> tediously type out the same line of code for each variable? 

This is the first Line of text in the help page:

"'scale' is generic function whose default method centers and/or scales the columns of a numeric matrix."

If you do not want the result as a matrix then you can use lapply on a dataframe.

-- 
David.

R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

-- 

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list