我有一个这种格式的文件。
F 0 0.700 99.000 -99.000 .10
T 0 TEMPMW1 25.000 500.000 .10
T 0 TEMPMW2 50.000 5000.000 .10
T 0 0.500 0.050 0.950 .10
T 0 0.500 0.050 0.950 .10
T 0 0.500 0.050 0.950 .10
我想用循环中的值替换变量,但从左开始不能超过13个字符。
格式基本上是:(L1,1X,I1,1X,3(F9.3,1X)
现在
x1 = 370.1164442 x2 = 4651.9392221
这样做
readLines(paramTemplate) %>% #Reads the template file and replaces the placeholders
gsub(pattern = "TEMPMW1", replace = format(x1, width=9, justify='none', nsmall=3, digits=3)) %>%
gsub(pattern = "TEMPMW2", replace = format(x2, width=9, justify='none', nsmall=3, digits=3))
正在移位这些值
F 0 0.700 99.000 -99.000 .10
T 0 370.116 25.000 500.000 .10
T 0 4651.939 50.000 5000.000 .10
T 0 0.500 0.050 0.950 .10
预期结果
F 0 0.700 99.000 -99.000 .10
T 0 370.116 25.000 500.000 .10
T 0 4651.939 50.000 5000.000 .10
T 0 0.500 0.050 0.950 .10
我该怎么做呢?
发布于 2018-07-24 04:20:39
一个有效的non-solution
:
使所有占位符大小相等。保持它对其他解决方案的开放。
T 0 TEMPMW1SS 25.000 500.000 .10
T 0 TEMPMW2SS 50.000 5000.000 .10
T 0 0.500 0.050 0.950 .10
T 0 0.500 0.050 0.950 .10
T 0 0.500 0.050 0.950 .10
https://stackoverflow.com/questions/51486373
复制相似问题