2

I need answers on this topic. 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 files 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.

4

1 回答 1

2

+1 用于lapply将所有数据集放在列表中。

如果我对您的理解正确,您可以执行以下替换:

myfiles <- lapply(myfiles, function(df)
                  data.frame(lapply(df, function(x) {
                             if(is.numeric(x))
                                 x[x == -999.99] <- NA
                             else x[x %in% c('T','C','A','F','Y')] <- NA
                             x
                  })
           )
于 2013-08-15T06:42:56.270 回答