Skip to content
Prev 293583 / 398503 Next

text replacement with a loop in a script file

Hello,


diegogiri wrote
Try

text <- c("<ARCHIVIO>                         <name> <definition>")

# I have a csv file like:
x <- read.csv(text="
NAME
alfa
beta
gamma
", header=TRUE, stringsAsFactors=FALSE)

pattern <- paste("<", names(x), ">", sep="")
sapply(unlist(x), function(y) sub(pattern, y, text, ignore.case=TRUE))

When you read the csv file from disk, don't forget setting the
stringsAsFactors option to FALSE.

Hope this helps,

Rui Barradas


--
View this message in context: http://r.789695.n4.nabble.com/text-replacement-with-a-loop-in-a-script-file-tp4608744p4608798.html
Sent from the R help mailing list archive at Nabble.com.