Skip to content

conditional replacement - readLines

2 messages · Christian Schulz, Uwe Ligges

#
Hi,

i have list with 2575  cgi files which i have read with readLines - all 
Lines have the type "chr".
Now i want replace the 2. line with a condition in 4. line and  write  
the files back  to dir.

How i could avoid the incompatible problem, or is it better
doing something with awk!?

 for (i in 1:2575){
datenrep <- 
ifelse(daten[[i]][4]=="type,1",cat(substr(as.character(paste(daten[[i]][2])),1,5),as.character(100)
,substr(as.character(paste(daten[[i]][2])),6,12),sep=""),daten[[i]][2])}
lfdn,1001081Error in "[<-"(`*tmp*`, test & !nas, value = NULL) :
        incompatible types

many thanks, christian
1 day later
#
Christian Schulz wrote:

            
You don't want to cat() here!
(Also, you do want to use "if(){} else{}" rather than "ifelse()".)

Uwe Ligges