0

Background: I am applying the slope and offset from my standard curve to my raw data. The raw data is organized in a data frame with "Group" on the Y axis and Time points on the X axis. Each group, A through F, has 12 rows and its own standard curve. The standard curve values are in a separate data frame.

Issue: I tried to write a loop ( for (char in abc)...) to go through each group and create a final data frame with all the raw data transformed but Im having an issue using the $ operator and the iterable variable (not sure what its called) i.e. stdcrv.data$char, this is the SLOPE step in the below code. I get a NULL value for SLOPE and stdcrv.data$char.

Can the $ opperator not be used with char? How should I fix this loop? I attached the 'Working Code' which runs and does what I need, I made one for each letter but I would rather have it running as a loop than six of those.

Loop Summary: The loop should go through each letter and subset the 12 rows of raw data per letter. Then it should create a variable of the unique slope and the unique offset from the stdcrv.data. The final line transforms the raw data by those variables and binds them to a new data frame. This is what is done in the working code, it just doesn't loop.

Still new to SO if Im putting too much info in my question let me know, thanks

raw.data:

Group 11:29  11:43  11:56  12:10  12:23   12:38   12:53   13:07   13:21   13:37   14:07   14:38   15:13
1     A 36090 123346 280239 529487 898173 1370663 1906590 2396293 2984783 3811666 5325242 6771652 8599776
2     A 33316 103971 245647 480937 826774 1256875 1680066 2174810 2621266 3327056 4733830 6035170 7601268

stdcrv.data:

 X            A            B            C            D            E            F
1  Slope 1.190980e+05 1.178085e+05 112511.14940 1.097752e+05 1.136168e+05 1.036628e+05
2 Offset 1.859640e+05 1.588433e+05  59179.53093 1.343089e+05 1.369816e+05 9.994541e+03

Working Code

A<-raw.data[grep("A",raw.data$Group),]
Asub<-A[2:15]
ASLOPE<-stdcrv.data$A[grep("Slope",stdcrv.data$X)]
AOFFSET<-stdcrv.data$A[grep("Offset",stdcrv.data$X)]
Final<- cbind(A[1],(Asub-AOFFSET)/ASLOPE)

B<-raw.data[grep("B",raw.data$Group),]
Bsub<-B[2:15]
BSLOPE<-stdcrv.data$B[grep("Slope",stdcrv.data$X)]
BOFFSET<-stdcrv.data$B[grep("Offset",stdcrv.data$X)]
Final<- rbind(Final,(cbind(B[1],(Bsub-BOFFSET)/BSLOPE)))

Attempt at Loop:

abc<- c('A', 'B', 'C', 'D','E','F')
for (char in abc){
  char.df <- raw.data[grep(char,raw.data$Group),]
  char.df.subset<-char.df[2:15]
  SLOPE<-stdcrv.data$char[grep("Slope",stdcrv.data$X)]
}
oguz ismail
  • 1
  • 16
  • 47
  • 69
HKlein
  • 11
  • 5

0 Answers0