r - Inserting NA after Test -
i have list full of of data.frames 2 columns, time , signal. data.frames results of gc chromatographic analysis process periodically sampled.
i want compare gc data i've collected.
i've written function convert times , peak areas percentage areas (excluding solvent peak) , relative retention times.
due nature of process, different gcs have differing numbers of peaks , therefore comparison isn't straightforward. impurities appear @ different parts of process , hence give peaks.
i want go on list , find longest vector of relative retention times (no problem). want use longest vector comparator , place na values @ relative retention times appear @ same time comparator not appear in other data.frames.
hence results of following list of relative retention times,
prac <- list(a=c(0.203,0.305,0.444,0.780,1.000,1.101,1.403), b=c(0.201,0.306,0.442,0.778,1.000,1.101,1.208,1.401))
where b comparator vector, should like
0.203 0.305 0.444 0.780 1.000 1.101 na 1.403 0.201 0.306 0.442 0.778 1.000 1.101 1.208 1.401
can suggest how might able start?
my first thought loop don't think work. please note there more 1 na values required.
(i plan collate percentage areas against comparator relative retention times chromatograms, if can beyond problem).
this 1 solution (brute force) 1 missing value:
prac <- list(a=c(0.203,0.305,0.444,0.780,1.000,1.101,1.403), b=c(0.201,0.306,0.442,0.778,1.000,1.101,1.208,1.401)) na.index <- which(abs(prac$b[1:length(prac$a)] - prac$a) > 0.05) newlist.a <- c(prac$a[1:na.index-1], na, prac$a[na.index])
this here should generizeable( depending on how data structured):
prac <- list(a=c(0.203,0.305,0.444,0.780,1.000,1.101,1.403), b=c(0.201,0.306,0.442,0.778,1.000,1.101,1.208,1.401)) for(i in seq_along(prac$a)) { if(abs(prac$b[i] - prac$a[i]) < 0.05) { prac$a[i] <- prac$a[i] } else { prac$a[i+1] <- prac$a[i] prac$a[i] <- na } }
kinda hard tell how generalize examples multiples nas without giving reproducible example, because right tapping in dark how data structured
Comments
Post a Comment