I have spectral data that I am trying to run PCA on. To learn how to do this I have created a matrix with two distinct groups and then pulled a file in that has typical wavelengths. I am pre-processing the data and have run into issues with baseline correction. I can do it with a for loop, but want to know if I can do it with apply instead. I get different errors depending on what I am trying and don't know if it is even possible. My most recent error is:
Error in matrix(0, np[1], np[2]) : non-numeric matrix extent.
I get this immediately after:
playdata.baseline<-apply(playdata,1, baseline,lambda=1,hwi=20,it=30,int=800,method='fillPeaks')
Can I use apply for the baseline function? If yes, why is it not working with the rest of the code that works fine using a for loop for baseline?
Here is what works:
#baseline corrections
playdata.baseline=matrix(0,ncol=nrow(playdata),nrow=ncol(playdata))
playdata.bc=c()
playdata=t(playdata)
for (n in 1:(length(playdata[,1]))){
playdata.bc=baseline(playdata[n,,drop=FALSE],
lambda=1, hwi=20, it=30,
int=800, method='fillPeaks')
playdata.baseline[n,]=playdata.bc@corrected
}
playdata=playdata.baseline
playdata=t(playdata)
Keeping everything the same until # baseline corrections, the apply attempt is as follows:
#baseline corrections
playdata=t(playdata)
playdata.baseline <- apply(playdata, 1, baseline, lambda=1, hwi=20,
it=30, int=800, method='fillPeaks')
playdata=t(playdata)