Quantcast

R help for read.table()

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

R help for read.table()

Gaurav Kumar-7



       
       
       
       
       
       

I've a table containing two columns
seperated by space, as shown below.
S:C 2.011085038928

S:A 21.496800549900762

S:J 0.183181039138149

P:E 9.641984304606304




I'm reading this table inside a loop
but unable to access the first column as file[i,1].
   

file <-
read.table("data.txt",header=FALSE)

for ( i in 1:nrow(file))
{

 cat(file[i,1],":")

 pvalue <-
2*(1-pnorm(abs(file[i,2])))

 cat(pvalue,"\n")

}




can anyone help  me how to read the
first column.



regards


Gaurav Kumar
www.gauravkumar.org

PhD Student, Chemistry and Biomolecular Sciences, Macquarie , Sydney, Australia.
MS (Computational Biology), NCBS-TIFR, Bangalore, India.


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

RES: R help for read.table()

Leandro Marino
Hi,
You didnt put the parameter sep=' ' in the read.table.

If you try to see str(file), i think you are going to see only one column.

read.table("data.txt",header=FALSE,sep=' ')

Atenciosamente,
Leandro Lins Marino
Centro de Avaliação
Fundação CESGRANRIO
Rua Santa Alexandrina, 1011 - 2º andar
Rio de Janeiro, RJ - CEP: 20261-903
R (21) 2103-9600 R.:236
  (21) 8777-7907
( [hidden email]

"Aquele que suporta o peso da sociedade
    é precisamente aquele que obtém
 as menores vantagens". (SMITH, Adam)

  Antes de imprimir pense em sua responsabilidade e compromisso com o MEIO AMBIENTE

Esta mensagem, incluindo seus anexos, pode conter informacoes privilegiadas e/ou de carater confidencial, nao podendo ser retransmitida sem autorizacao do remetente. Se voce nao e o destinatario ou pessoa autorizada a recebe-la, informamos que o seu uso, divulgacao, copia ou arquivamento sao proibidos.
Portanto, se você recebeu esta mensagem por engano, por favor, nos informe respondendo imediatamente a este e-mail e em seguida apague-a.

-----Mensagem original-----
De: [hidden email] [mailto:[hidden email]] Em nome de Gaurav Kumar
Enviada em: quarta-feira, 20 de janeiro de 2010 08:05
Para: [hidden email]
Assunto: [R] R help for read.table()




       
       
       
       
       
       

I've a table containing two columns
seperated by space, as shown below.
S:C 2.011085038928

S:A 21.496800549900762

S:J 0.183181039138149

P:E 9.641984304606304




I'm reading this table inside a loop
but unable to access the first column as file[i,1].
   

file <-
read.table("data.txt",header=FALSE)

for ( i in 1:nrow(file))
{

 cat(file[i,1],":")

 pvalue <-
2*(1-pnorm(abs(file[i,2])))

 cat(pvalue,"\n")

}




can anyone help  me how to read the
first column.



regards


Gaurav Kumar
www.gauravkumar.org

PhD Student, Chemistry and Biomolecular Sciences, Macquarie , Sydney, Australia.
MS (Computational Biology), NCBS-TIFR, Bangalore, India.


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

Re: [R] R help for read.table()

djmuseR
In reply to this post by Gaurav Kumar-7
R does vectorized arithmetic. Your loop was superfluous. Observe:

> x <- read.table(textConnection("
+ S:C 2.011085038928
+ S:A 21.496800549900762
+ S:J 0.183181039138149
+ P:E 9.641984304606304"))
> x
   V1         V2
1 S:C  2.0110850
2 S:A 21.4968005
3 S:J  0.1831810
4 P:E  9.6419843
> transform(x, pval = 2 * (1 - pnorm(abs(V2))))
   V1         V2       pval
1 S:C  2.0110850 0.04431648
2 S:A 21.4968005 0.00000000
3 S:J  0.1831810 0.85465597
4 P:E  9.6419843 0.00000000

HTH,
Dennis


On Wed, Jan 20, 2010 at 3:04 AM, Gaurav Kumar <[hidden email]>wrote:

>
>
>
>
>
>
>
>
>
>
> I've a table containing two columns
> seperated by space, as shown below.
> S:C 2.011085038928
>
> S:A 21.496800549900762
>
> S:J 0.183181039138149
>
> P:E 9.641984304606304
>
>
>
>
> I'm reading this table inside a loop
> but unable to access the first column as file[i,1].
>
>
> file <-
> read.table("data.txt",header=FALSE)
>
> for ( i in 1:nrow(file))
> {
>
>  cat(file[i,1],":")
>
>  pvalue <-
> 2*(1-pnorm(abs(file[i,2])))
>
>  cat(pvalue,"\n")
>
> }
>
>
>
>
> can anyone help  me how to read the
> first column.
>
>
>
> regards
>
>
> Gaurav Kumar
> www.gauravkumar.org
>
> PhD Student, Chemistry and Biomolecular Sciences, Macquarie , Sydney,
> Australia.
> MS (Computational Biology), NCBS-TIFR, Bangalore, India.
>
>
>        [[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.
>
>

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

Re: [R] RES: R help for read.table()

Gaurav Kumar-7
In reply to this post by Leandro Marino
Hi Leonard,

Thanks for your quick response.
i tired using the sep=" " in read.table() function, but still can't access the first column.
checked , str(file), showing the $V1 variable...but can't access the first column inside the loop.

regards
Gaurav Kumar
www.gauravkumar.org

PhD Student, Chemistry and Biomolecular Sciences, Macquarie , Sydney, Australia.
MS (Computational Biology), NCBS-TIFR, Bangalore, India.



--- On Wed, 20/1/10, Leandro Marino <[hidden email]> wrote:

From: Leandro Marino <[hidden email]>
Subject: RES: [R] R help for read.table()
To: [hidden email], [hidden email]
Date: Wednesday, 20 January, 2010, 5:46 PM

Hi,
You didnt put the parameter sep=' ' in the read.table.

If you try to see str(file), i think you are going to see only one column.

read.table("data.txt",header=FALSE,sep=' ')

Atenciosamente,
Leandro Lins Marino
Centro de Avaliação
Fundação CESGRANRIO
Rua Santa Alexandrina, 1011 - 2º andar
Rio de Janeiro, RJ - CEP: 20261-903
R (21) 2103-9600 R.:236
  (21) 8777-7907
( [hidden email]

"Aquele que suporta o peso da sociedade
    é precisamente aquele que obtém
 as menores vantagens". (SMITH, Adam)

  Antes de imprimir pense em sua responsabilidade e compromisso com o MEIO AMBIENTE

Esta mensagem, incluindo seus anexos, pode conter informacoes privilegiadas e/ou de carater confidencial, nao podendo ser retransmitida sem autorizacao do remetente. Se voce nao e o destinatario ou pessoa autorizada a recebe-la, informamos que o seu uso, divulgacao, copia ou arquivamento sao proibidos.
Portanto, se você recebeu esta mensagem por engano, por favor, nos informe respondendo imediatamente a este e-mail e em seguida apague-a.

-----Mensagem original-----
De: [hidden email] [mailto:[hidden email]] Em nome de Gaurav Kumar
Enviada em: quarta-feira, 20 de janeiro de 2010 08:05
Para: [hidden email]
Assunto: [R] R help for read.table()




   
   
   
   
   
   

I've a table containing two columns
seperated by space, as shown below.
S:C 2.011085038928

S:A 21.496800549900762

S:J 0.183181039138149

P:E 9.641984304606304




I'm reading this table inside a loop
but unable to access the first column as file[i,1].
   

file <-
read.table("data.txt",header=FALSE)

for ( i in 1:nrow(file))
{

 cat(file[i,1],":")

 pvalue <-
2*(1-pnorm(abs(file[i,2])))

 cat(pvalue,"\n")

}




can anyone help  me how to read the
first column.



regards


Gaurav Kumar
www.gauravkumar.org

PhD Student, Chemistry and Biomolecular Sciences, Macquarie , Sydney, Australia.
MS (Computational Biology), NCBS-TIFR, Bangalore, India.


    [[alternative HTML version deleted]]





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

Re: [R] R help for read.table()

Gaurav Kumar-7
In reply to this post by djmuseR
Thank Dennis!!!.....it works....

regards

Gaurav Kumar
www.gauravkumar.org

PhD Student, Chemistry and Biomolecular Sciences, Macquarie , Sydney, Australia.
MS (Computational Biology), NCBS-TIFR, Bangalore, India.



--- On Wed, 20/1/10, Dennis Murphy <[hidden email]> wrote:

From: Dennis Murphy <[hidden email]>
Subject: Re: [R] R help for read.table()
To: [hidden email]
Cc: [hidden email]
Date: Wednesday, 20 January, 2010, 4:43 PM

R does vectorized arithmetic. Your loop was superfluous. Observe:

> x <- read.table(textConnection("
+ S:C 2.011085038928
+ S:A 21.496800549900762
+ S:J 0.183181039138149
+ P:E 9.641984304606304"))

> x
   V1         V2
1 S:C  2.0110850
2 S:A 21.4968005
3 S:J  0.1831810
4 P:E  9.6419843
> transform(x, pval = 2 * (1 - pnorm(abs(V2))))
   V1         V2       pval
1 S:C  2.0110850 0.04431648

2 S:A 21.4968005 0.00000000
3 S:J  0.1831810 0.85465597
4 P:E  9.6419843 0.00000000

HTH,
Dennis


On Wed, Jan 20, 2010 at 3:04 AM, Gaurav Kumar <[hidden email]> wrote:





















I've a table containing two columns

seperated by space, as shown below.

S:C 2.011085038928



S:A 21.496800549900762



S:J 0.183181039138149



P:E 9.641984304606304









I'm reading this table inside a loop

but unable to access the first column as file[i,1].





file <-

read.table("data.txt",header=FALSE)



for ( i in 1:nrow(file))

{



 cat(file[i,1],":")



 pvalue <-

2*(1-pnorm(abs(file[i,2])))



 cat(pvalue,"\n")



}









can anyone help  me how to read the

first column.







regards





Gaurav Kumar

www.gauravkumar.org



PhD Student, Chemistry and Biomolecular Sciences, Macquarie , Sydney, Australia.

MS (Computational Biology), NCBS-TIFR, Bangalore, India.





        [[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.





        [[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.
Loading...