Skip to content
Prev 322577 / 398500 Next

Help

HI,

"Find 'T','C','A','F' and 'Y', delete them from all the 110 files"
I assume that you meant to replace it with NA.


set.seed(28)
myfiles<- lapply(1:5,function(i) as.data.frame(matrix(sample(c(LETTERS,"-999.99M"),40*i,replace=TRUE),ncol=(40*i)/8),stringsAsFactors=FALSE))
?myfiles[[1]]
#? V1 V2?????? V3 V4 V5
#1? A? P??????? K? O? Y
#2? C? Z??????? S? M? Y
#3? M? S -999.99M? G? I
#4? X? R??????? M? G? X
#5? C? Q??????? G? A? P
#6? U? W??????? G? B? K
#7? A? N??????? Z? X? R
#8? X? I??????? F? M? K


res<-lapply(myfiles,function(x) {x1<-unlist(x); x1[x1%in% c("-999.99M","T","C","A","F","Y")]<-NA;as.data.frame(matrix(x1,ncol=ncol(x)),stringsAsFactors=FALSE)})

res[[1]]
?# ? V1 V2?? V3?? V4?? V5
#1 <NA>? P??? K??? O <NA>
#2 <NA>? Z??? S??? M <NA>
#3??? M? S <NA>??? G??? I
#4??? X? R??? M??? G??? X
#5 <NA>? Q??? G <NA>??? P
#6??? U? W??? G??? B??? K
#7 <NA>? N??? Z??? X??? R
#8??? X? I <NA>??? M??? K

lapply(seq_along(res),function(i) write.table(res[[i]],paste0("file",i,".txt"),row.names=FALSE,quote=FALSE))
A.K.


----- Original Message -----
From: Zilefac Elvis <zilefacelvis at yahoo.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc: 
Sent: Saturday, April 27, 2013 11:20 AM
Subject: [R] Help

Hello,



I have a question and need your help urgently. I am new to R but want to learn it.

I have several files in a folder which I have imported to R using :
temp = list.files(pattern="*.txt")
The resulting files are on the workspace stored as List[110]. So they are 110 files in the list. Each file has several different columns and rows.
My question: I would like to find and replace -999.99M with NA; Find 'T','C','A','F' and 'Y', delete them from all the 110 files.
Then, I want to write.table all the corrected files back to a folder on my computer.
Thanks for your help.
Atem.
?