Skip to content

Digit positions in writing files

1 message · Marco

#
Hi, romunov:

Sorry, I am quite unfamiliar with the mail system, and send the
example only to Roman:

This is the data segment and script that I used to replace the
coordinate, and the result is constant space in between each columns:

####old coordinates
#colnames
##site prec site   lat    lon
 7969    0 55248   32.30   84.05
 7970    3 55279   31.37   90.02
 7971    0 55294   32.27   91.67
 7972    0 55299   31.48   92.07
 7973    0 55437   30.55   81.43
 7974    0 55472   30.95   88.63
 7975    0 55493   30.73   92.45
 7976    0 55569   29.07   87.68
 7977    1 55578   29.25   88.88
 7978    0 55591   29.67   91.13
 7979    0 55598   29.23   91.77
 7980    2 55664   28.63   87.08
 7981    0 55680   29.00   89.63
 7982    0 55690   28.70   91.63
 7983   12 55696   28.42   92.47
###new coordinates
#site		lat		lon
55248	32.15	84.42
55294	32.35	91.1
55437	30.28	81.25
55493	30.48	91.1
55569	29.08	87.6
55598	29.25	91.77
55680	28.92	89.6
55690	27.98	91.95
56202	30.67	93.28
56312	29.67	94.33

##My searching ID
findlist<-c(55248,55294,55437,55493,55569,55598,55680,55690)

old<-read.table('old.txt',head=F,sep='')
names(old)<-c('ID','value','site','lat','lon')
new<-read.table('new.txt',head=F,sep='')
names(x)<-c('site','lat','lon')
for (j in findlist){
old$lat[old$site==j]<-new$lat[new$site==j]
old$lon[old$site==j]<-new$lon[new$site==j]
}
write.table(old,'replaced.txt',row.names = F,col.names =F,eol='\r',sep='   ')

The script looks very silly, but that what I can do in my skill.

My aim again is to obtain the replaced.txt that confirm to the
required format, ie: constant digit length for each column, not
constant space in between.
Anyone could help me out?

Cheers,
Marco


2010/12/1 romunov <romunov at gmail.com>: