Skip to content
Prev 148825 / 398498 Next

Insert text in data.frame

Try this:

x <- read.table(textConnection("Conc             Lat       Lon    Depth

Point0000   56.25    -5.65      70

Point0001   56.55    -5.35      85

Point0002   56.25    -5.65      65

Point0003   56.37    -5.21      80

Point0004   56.45    -5.23      30

Point0000   56.25    -5.55      75

Point0001   56.35    -5.34      85

Point0002   56.28    -5.18      75

Point0003   56.25    -5.10      45

Point0000   56.55    -5.65      50"), header=TRUE)
closeAllConnections()
# get the text strings for output
y <- capture.output(write.table(x, quote=FALSE, row.names=FALSE,
col.names=FALSE))
output <- file('tempxx.txt', 'w')
for (i in y){
    if (length(grep("Point0000", i)) > 0)cat("\nObject=Line\nColor
RED\nStyle SOLID\n", file=output)
    cat(i, "\n", file=output)
}
close(output)


It produces and output file:


Object=Line
Color RED
Style SOLID
Point0000 56.25 -5.65 70
Point0001 56.55 -5.35 85
Point0002 56.25 -5.65 65
Point0003 56.37 -5.21 80
Point0004 56.45 -5.23 30

Object=Line
Color RED
Style SOLID
Point0000 56.25 -5.55 75
Point0001 56.35 -5.34 85
Point0002 56.28 -5.18 75
Point0003 56.25 -5.1 45

Object=Line
Color RED
Style SOLID
Point0000 56.55 -5.65 50
On Wed, Jul 2, 2008 at 10:39 AM, Mafalda Viana <M.Viana at marlab.ac.uk> wrote: