Hi,
If you wanted to delete "T", "C","A", "F" and "Y" and replace "-999.99M" with 
NA, it is possible, but the result would be stored in a list if 
the number of elements deleted from each of the columns are different.   As you 
didn't provide any reproducible example, I don't know whether equal number of 
elements are replaced from each columns or not..

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))
res<-lapply(myfiles,function(x){x[x=="-999.99M"]<-NA;lapply(x,function(y) 
y[!y%in%c("T","C","A","F","Y")])})
res[[1]]
#$V1
#[1] "M" "X" "U" "X"
#
#$V2
#[1] "P" "Z" "S" "R" "Q" "W" "N" "I"
#
#$V3
#[1] "K" "S" NA  "M" "G" "G" "Z"
#
#$V4
#[1] "O" "M" "G" "G" "B" "X" "M"
#
#$V5
#[1] "I" "X" "P" "K" "R" "K"

A.K.
________________________________
From: "zilefacel...@yahoo.com" <zilefacel...@yahoo.com>
To: arun <smartpink...@yahoo.com> 
Cc: R help <r-help@r-project.org> 
Sent: Saturday, April 27, 2013 9:41 PM
Subject: Re: Re: [R] Help







Hi A.K,


Thanks for  this great help. I wish to find -999.99M and replace with NA. All 
others like T, A, F etc should be deleted from the files.





Thanks for much.

------ Original Message ------



>From : arun
>To : Zilefac Elvis;
>Cc : R help;
>Sent : 27-04-2013 16:29
>Subject : Re: [R] 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    P    K    O  
#2    Z    S    M  
#3    M  S      G    I
#4    X  R    M    G    X
#5    Q    G      P
#6    U  W    G    B    K
#7    N    Z    X    R
#8    X  I      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  
To: "r-help@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")
>myfiles = lapply(temp, read.delim)
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. ________________________________
From: "r-help-requ...@r-project.org"   Sent: Friday, April 26, 2013 11:08 AM
Subject: confirm bfdc3137cee0135cf3c616295c9d0e2b3adfd392 Mailing list 
subscription confirmation notice for mailing list R-help We have received a 
request from 129.132.148.130 for subscription of r-help@r-project.org mailing 
list.  To confirm that you want to be
added to this mailing list, simply reply to this message, keeping the
Subject: header intact.  Or visit this web page:    
https://stat.ethz.ch/mailman/confirm/r-help/bfdc3137cee0135cf3c616295c9d0e2b3adfd392
 Or include the following line -- and only the following line -- in a
message to r-help-requ...@r-project.org:    confirm 
bfdc3137cee0135cf3c616295c9d0e2b3adfd392 Note that simply sending a `reply' to 
this message should work from
most mail readers, since that usually leaves the Subject: line in the
right form (additional "Re:" text in the Subject: is okay). If you do not wish 
to be subscribed to this list, please simply
disregard this message.  If you think you are being maliciously
subscribed to the list, or have any other questions, send them to
r-help-ow...@r-project.org.    [[alternative HTML version deleted]] 
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.  

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to