[R] Writing integers in "write.matrix" function

Mohsen Jafarikia jafarikia at gmail.com
Sun Feb 25 18:20:17 CET 2007


Hello everyone,

I am using the following program to get the p-value of some numbers
(column 'LR' of the data.dat file). I want to write the 1st and 2nd
column of the output file (data.out) as an integer while the program
change them. Could anybody please tell me how I can write
the code which writes the values of the first two columns as integer?

For your convenience, I have attached the input and output files.
I should indicate that I have already sent this message but I could not
apply your comments.
Thanks

library ('MASS')
MP<-read.table(file='data.dat')
names(MP)<-c('B','R','S','L','LR','Q')
a<-as.matrix((1-pchisq(MP$LR, df=1)))
b<-cbind(MP$B,MP$R,a,MP$S,MP$L,MP$LR,MP$Q)
write.matrix(b,'data.out')



These are the files if you don't like to open the attached file!



data.dat:

  1   7   1.704094  10.61   0.874286  0.00

  2   7   1.955271   2.82   1.001429  0.00

  3   6   2.960459   3.74   1.548667  0.00

  4   4   6.120956   5.83   3.929000  1.92



data.out:

c d

1.000000e+00 7.000000e+00 3.497715e-01 1.704094e+00 1.061000e+01
8.742860e-01 0.000000e+00

2.000000e+00 7.000000e+00 3.169650e-01 1.955271e+00 2.820000e+00
1.001429e+00 0.000000e+00

3.000000e+00 6.000000e+00 2.133323e-01 2.960459e+00 3.740000e+00
1.548667e+00 0.000000e+00

4.000000e+00 4.000000e+00 4.746016e-02 6.120956e+00 5.830000e+00
3.929000e+00 1.920000e+00
-------------- next part --------------
  1   7   1.704094  10.61   0.874286  0.00
  2   7   1.955271   2.82   1.001429  0.00
  3   6   2.960459   3.74   1.548667  0.00
  4   4   6.120956   5.83   3.929000  1.92



-------------- next part --------------
c d     
1.000000e+00 7.000000e+00 3.497715e-01 1.704094e+00 1.061000e+01 8.742860e-01 0.000000e+00
2.000000e+00 7.000000e+00 3.169650e-01 1.955271e+00 2.820000e+00 1.001429e+00 0.000000e+00
3.000000e+00 6.000000e+00 2.133323e-01 2.960459e+00 3.740000e+00 1.548667e+00 0.000000e+00
4.000000e+00 4.000000e+00 4.746016e-02 6.120956e+00 5.830000e+00 3.929000e+00 1.920000e+00


More information about the R-help mailing list