Re: [R] standardize columns selectively within a dataframe

2010-09-01 Thread Olga Lyashevska
On Wed, 2010-09-01 at 12:42 -0400, David Winsemius wrote: > I suspect you might have tried (df-mean(df))/sd(x) and gotten > unsatisfactory results; I know I did. yes, indeed! a few times, but why is that? > If you had really wanted to > persist and do it from first principles, so to speak,

Re: [R] standardize columns selectively within a dataframe

2010-09-01 Thread David Winsemius
On Sep 1, 2010, at 10:42 AM, David Winsemius wrote: On Sep 1, 2010, at 10:35 AM, Olga Lyashevska wrote: Dear all, I have a dataframe: df<-dataframe(a=c(1,2,3),b=c(4,5,6),c=c(7,8,9),d=c(10,11,12)) I want to obtain a new dataframe with columns a and b being standardized ((x-mean(x))/sd(x)

Re: [R] standardize columns selectively within a dataframe

2010-09-01 Thread Olga Lyashevska
Thanks! It is exactly what I was looking for! Cheers Olga __ R-help@r-project.org mailing list 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

Re: [R] standardize columns selectively within a dataframe

2010-09-01 Thread Adaikalavan Ramasamy
If you want to scale within columns, you could try cbind( scale(df[,1:2]), df[ ,-c(1:2)] ) a b c d 1 -1 -1 7 10 2 0 0 8 11 3 1 1 9 12 and it is data.frame() btw. On 01/09/2010 15:35, Olga Lyashevska wrote: Dear all, I have a dataframe: df<-dataframe(a=c(1,2,3),b=c(4,5,6),c=c(7,

Re: [R] standardize columns selectively within a dataframe

2010-09-01 Thread David Winsemius
On Sep 1, 2010, at 10:35 AM, Olga Lyashevska wrote: Dear all, I have a dataframe: df<-dataframe(a=c(1,2,3),b=c(4,5,6),c=c(7,8,9),d=c(10,11,12)) I want to obtain a new dataframe with columns a and b being standardized ((x-mean(x))/sd(x)); the other two columns (c,d) I want to leave unchange

[R] standardize columns selectively within a dataframe

2010-09-01 Thread Olga Lyashevska
Dear all, I have a dataframe: df<-dataframe(a=c(1,2,3),b=c(4,5,6),c=c(7,8,9),d=c(10,11,12)) I want to obtain a new dataframe with columns a and b being standardized ((x-mean(x))/sd(x)); the other two columns (c,d) I want to leave unchanged. What is the best way to achieve this? I have been try