Quantcast

would you give me your hand to standardize columns in a matrix?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

would you give me your hand to standardize columns in a matrix?

Kristi Glover

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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: would you give me your hand to standardize columns in a matrix?

Rui Barradas
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]]
>
> ______________________________________________
> [hidden email] 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.
>

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: would you give me your hand to standardize columns in a matrix?

Rolf Turner-3
In reply to this post by Kristi Glover
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

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: would you give me your hand to standardize columns in a matrix?

arun kirshna
In reply to this post by Kristi Glover


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 <[hidden email]>
To: R-help <[hidden email]>
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]]

______________________________________________
[hidden email] 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.


______________________________________________
[hidden email] 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.
Loading...