Kristi Glover
2012-Jun-28 19:11 UTC
[R] would you give me your hand to standardize columns in a matrix?
Hi R User, Would you give me your hand to standardize some columns in a matrix? I have included the example table.> dput(test)structure(list(X = c(1, 2, 3, 4, 5, 6), Y = c(4, 5, 6, 7, 8, 9), temp = c(0.818, 0.113, 0.256, 0.587, 0.955, 0.207), oxy = c(0.797, 0.487, 0.727, 0.128, 0.514, 0.031)), .Names = c("X", "Y", "temp", "oxy"), row.names = c(NA, -6L), class = "data.frame") here I wanted to standardize the variable "temp" and "oxy". I have more than 75 variables so that I need to apply 'loop'. Could you help me to make a loop? I wrote following but, it did not work. for (i in 1:n(test)){ for (t in 1:T (test)) x.z[i] = (x[i,t] - mean(x(i,]/sd)x[i,]) } Thanks for your help. Kristi [[alternative HTML version deleted]]
Rui Barradas
2012-Jun-29 07:40 UTC
[R] would you give me your hand to standardize columns in a matrix?
Hello,
Try
scale(test[, c("temp", "oxy")])
Hope this helps,
Rui Barradas
Em 28-06-2012 20:11, Kristi Glover escreveu:>
> Hi R User,
> Would you give me your hand to standardize some columns in a matrix?
>
> I have included the example table.
>
>> dput(test)
> structure(list(X = c(1, 2, 3, 4, 5, 6), Y = c(4, 5, 6, 7, 8,
> 9), temp = c(0.818, 0.113, 0.256, 0.587, 0.955, 0.207), oxy = c(0.797,
> 0.487, 0.727, 0.128, 0.514, 0.031)), .Names = c("X",
"Y", "temp",
> "oxy"), row.names = c(NA, -6L), class = "data.frame")
>
> here I wanted to standardize the variable "temp" and
"oxy". I have more than 75 variables so that I need to apply
'loop'.
>
> Could you help me to make a loop?
>
> I wrote following but, it did not work.
>
> for (i in 1:n(test)){
> for (t in 1:T (test)) x.z[i] = (x[i,t] - mean(x(i,]/sd)x[i,])
> }
>
> Thanks for your help.
>
> Kristi
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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-contained, reproducible code.
>
Rolf Turner
2012-Jun-29 09:58 UTC
[R] would you give me your hand to standardize columns in a matrix?
On 29/06/12 07:11, Kristi Glover wrote:> Hi R User, > Would you give me your hand to standardize some columns in a matrix?No I would not give you my hand. I'm already married! :-) cheers, Rolf Turner
arun
2012-Jun-29 13:07 UTC
[R] would you give me your hand to standardize columns in a matrix?
Hi, you could use scale() test[,3:4]<-scale(test[,3:4])> test???? X Y?????? temp??????? oxy [1,] 1 4? 0.9408239? 1.1264280 [2,] 2 5 -1.0772720? 0.1277835 [3,] 3 6 -0.6679277? 0.9009276 [4,] 4 7? 0.2795755 -1.0287112 [5,] 5 8? 1.3329929? 0.2147622 [6,] 6 9 -0.8081926 -1.3411902 A.K. ----- Original Message ----- From: Kristi Glover <kristi.glover at hotmail.com> To: R-help <r-help at r-project.org> Cc: Sent: Thursday, June 28, 2012 3:11 PM Subject: [R] would you give me your hand to standardize columns in a matrix? Hi R User, Would you give me your hand to standardize some columns in a matrix? I have included the example table.> dput(test)structure(list(X = c(1, 2, 3, 4, 5, 6), Y = c(4, 5, 6, 7, 8, 9), temp = c(0.818, 0.113, 0.256, 0.587, 0.955, 0.207), oxy = c(0.797, 0.487, 0.727, 0.128, 0.514, 0.031)), .Names = c("X", "Y", "temp", "oxy"), row.names = c(NA, -6L), class = "data.frame") here I wanted to standardize the variable "temp" and "oxy". I have more than 75 variables so that I need to apply 'loop'. Could you help me to make a loop? I wrote following but, it did not work. for (i in 1:n(test)){ for (t in 1:T (test)) x.z[i] = (x[i,t] - mean(x(i,]/sd)x[i,]) } Thanks for your help. Kristi ??? ??? ??? ? ??? ??? ? ??? [[alternative HTML version deleted]] ______________________________________________ R-help at 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-contained, reproducible code.