批量修改csv文件中的Sample type列
setwd("C:/Users/na/Desktop/cai_table/cai/PRJ20230703_4")
files_name<-list.files("C:/Users/na/Desktop/cai_table/cai/PRJ20230703_4",pattern = "?.csv",full.names = TRUE)
length(files_name)
tmp<-list()
filenames = paste0("C:/Users/na/Desktop/cai_table/cai/PRJ20230703_4/",1:length(files_name),".csv")
for (i in 1:length(files_name)){
tmp[[i]]=read.csv(files_name[i],sep = ",",quote = "\"")
mapvalues(tmp[[i]]$"Sample type",c("serum"),c("urine"))
write.csv(tmp[[i]], sep =",",file=filenames[i],row.names = TRUE, col.names =TRUE)}
但是报错The following from
values were not present in x
: serum,想问一下该怎么解决