使用R将.sp文件(来自Perkin Elmer)合并到矩阵中

使用R将.sp文件(来自Perkin Elmer)合并到矩阵中,r,matrix,merge,R,Matrix,Merge,我是R方面的新手。我有分光光度计的数据,我想一次性处理所有数据 我有一个巨大的目录,每个样本有45个.sp文件(目前大约有200个样本)。我想通过将45个文件合并成一个矩阵,并将发射和提取作为列和行名称,为每个样本构建一个矩阵。文件名定义为:blahblah#01.sp、blahblah#02.sp到blahblah#45.sp(对于第一个示例)、toptop#01.sp、toptop#45.sp,在同一目录中,我有所有其他示例 是否可以将具有相同前缀(带有#01.sp..)的所有sp文件合并到

我是R方面的新手。我有分光光度计的数据,我想一次性处理所有数据

我有一个巨大的目录,每个样本有45个.sp文件(目前大约有200个样本)。我想通过将45个文件合并成一个矩阵,并将发射和提取作为列和行名称,为每个样本构建一个矩阵。文件名定义为:blahblah#01.sp、blahblah#02.sp到blahblah#45.sp(对于第一个示例)、toptop#01.sp、toptop#45.sp,在同一目录中,我有所有其他示例

是否可以将具有相同前缀(带有#01.sp..)的所有sp文件合并到一个矩阵中,并且对于所有示例

到目前为止,我已经尝试过:

## Set up data paths and read mask from file
setwd("C:/EEMs/")
getwd()

## Define paths for data, results table
datainpath<-"C:/EEMs/rawdata/"
dataoutpath<-"C:/EEMs/results/"


## Get list of sp files in the data directory that will be processed and print a list
files<-list.files(datainpath,pattern="\\.sp$")
print(files)

filename<-substring(files,1,nchar(files)-6)
print(filename)


### - 2. Define excitation and emission ranges for matrix
emission<-seq(250,600.5,0.5) # define emission wavelength range for matrix (start, finish, by) (nm)
excitation<-seq(200,420,5)# define excitation wavelength range for matrix (start, finish, by) (nm)
# Number of files per spectral
nfic<-45
# # Number of measurements per spectral
nc<-702

### - 3. Read in sample and blank EEMs files
## - 3.1.: Start loop through files in data folder
for (Samplefile in files) {

filename2<-paste(dataoutpath,filename,"#",as.character(0),as.character(1),".sp",sep="")
fich<-matrix(scan(filename2,skip=54),ncol=2,byrow=T)

dataechant<-matrix(NA,nrow=nc,ncol=nfic)
dimnames(dataechant)<-list(as.character(emission),as.character(excitation))
dataechant[,1]<-fich[,2]
for (i in 2:9)

{
filename2<-paste(dataoutpath,filename,"#",as.character(0),as.character(i),".sp",sep="")
fich<-matrix(scan(filename2,skip=54),ncol=2,byrow=T)
dataechant[,i]<-fich[,2]
}
for (i in 10:45)
 {
filename2<-paste(dataoutpath,filename,"#",as.character(i),".sp",sep="")
fich<-matrix(scan(filename2,skip=54),ncol=2,byrow=T)
dataechant[,i]<-fich[,2]
}
}

#Export to EEM result dir 
write.csv2(dataechant,paste("results/",filename,".csv"))
##设置数据路径并从文件中读取掩码
setwd(“C:/EEMs/”)
getwd()
##定义数据、结果表的路径

欢迎来到StackOverflow。这里有一个使用软件的提示:单独尝试每个步骤,看看输出是否符合您的要求。然后再回复我们关于没有产生预期结果的步骤。嗨,谢谢你的建议。我已尝试打印文件列表。没关系。。。然后,我想知道如何减少具有相同前缀的文件列表。这个新列表将用于运行另一个脚本,希望如此。