[R] conditional replacement - readLines
Uwe Ligges
ligges at statistik.uni-dortmund.de
Sat Nov 27 17:20:09 CET 2004
Christian Schulz wrote:
> 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)
You don't want to cat() here!
(Also, you do want to use "if(){} else{}" rather than "ifelse()".)
Uwe Ligges
> ,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
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
More information about the R-help
mailing list