작성. 모든 DT는 동일한 차원을가집니다. 여기 내 시도가 작동 :복사 짝수 열과 2 data.tables에서 홀수 것들을 뺀 & I 새로운 DT 심지어 열 <code>DT_resampled_final</code>에서 심지어 사람과 같은 이상한 사람 <code>DT_resampled_final</code> 및 <code>baseline_final</code> 간의 감산을 가져야한다 (<code>DT_final_LW_corr_baseline_sub</code>)가 필요 3 일
# Subtract baseline
DT_final_LW_corr_baseline_sub <- DT_resampled_final
i==1
for(i in 1:(numLW*2)){
if (!i %% 2==FALSE)
DT_final_LW_corr_baseline_sub[[i]] <- DT_resampled_final[[i]]
else {
DT_final_LW_corr_baseline_sub[[i]] <- DT_resampled_final[[i]]-baseline_final[[i]]
}
}
짧은 방법으로 할 수있는 방법이 있습니까? 예를 들어 루프를 사용하지 않고. 처음으로 코드를 작성하는 방법을 배우면서 초기에 나쁜 습관을 피하기 위해 몇 가지 피드백을 받고 싶습니다.
> dput(DT_resampled_final)
structure(list(`Raman shift (cm-1)` = c(50, 51, 52, 53, 54, 55,
56, 57, 58), HKU47_PSG_1_LW_0.txt = c(2.79147734046395, 3.12736782243076,
3.48956530852053, 3.91369820172483, 4.38198578134454, 4.88017327696127,
5.39373038518585, 5.90764948375938, 6.41547186798507), `Raman shift (cm-1)` = c(50,
51, 52, 53, 54, 55, 56, 57, 58), HKU47_PSG_1_LW_1.txt = c(2.80309121136158,
3.13172873120713, 3.49064185427554, 3.92083378212472, 4.38170006196362,
4.86333787529566, 5.41898234137124, 5.96816896624743, 6.45359586105501
), `Raman shift (cm-1)` = c(50, 51, 52, 53, 54, 55, 56, 57, 58
), HKU47_PSG_1_LW_2.txt = c(2.81531357970881, 3.13794190850462,
3.49352178106289, 3.92668050936782, 4.39913358215528, 4.89819532764696,
5.44873800963596, 5.99763728207632, 6.51413470312863), `Raman shift (cm-1)` = c(50,
51, 52, 53, 54, 55, 56, 57, 58), HKU47_PSG_1_LW_3.txt = c(2.77300320344437,
3.11330661799265, 3.4831985430277, 3.92275162880708, 4.39475831745469,
4.8887413823001, 5.42293580079945, 5.95922687586664, 6.48438977785762
)), .Names = c("Raman shift (cm-1)", "HKU47_PSG_1_LW_0.txt",
"Raman shift (cm-1)", "HKU47_PSG_1_LW_1.txt", "Raman shift (cm-1)",
"HKU47_PSG_1_LW_2.txt", "Raman shift (cm-1)", "HKU47_PSG_1_LW_3.txt"
), row.names = c(NA, -9L), class = c("data.table", "data.frame"
), .internal.selfref = <pointer: 0x0000000000100788>)
과 : 재현 예를없이
> dput(baseline_final)
structure(list(baseline_final = c(50, 51, 52, 53, 54, 55, 56,
57, 58), HKU47_PSG_1_LW_0.txt = c(2.57151934485739, 2.98291744761488,
3.42744260714059, 3.8986361182227, 4.39003927564949, 4.89519337420913,
5.40763970869006, 5.92091957388055, 6.42857426456877), V2 = c(50,
51, 52, 53, 54, 55, 56, 57, 58), HKU47_PSG_1_LW_1.txt = c(4.02555110741741,
3.72997378256628, 3.71798587071498, 3.93228548539923, 4.3155707401479,
4.81053974849669, 5.35989062397721, 5.90632148012082, 6.39253043046165
), V2 = c(50, 51, 52, 53, 54, 55, 56, 57, 58), HKU47_PSG_1_LW_2.txt = c(3.2465748229348,
3.32636445475191, 3.56085310009485, 3.91928231791712, 4.37089366717112,
4.88492870681023, 5.43062899578865, 5.97723609305751, 6.49399155757146
), V2 = c(50, 51, 52, 53, 54, 55, 56, 57, 58), HKU47_PSG_1_LW_3.txt = c(2.77906856332555,
3.08807780450024, 3.46763774953217, 3.90452356871538, 4.38551043234384,
4.89737351071187, 5.42688797411364, 5.96082899284301, 6.48597173719406
)), .Names = c("baseline_final", "HKU47_PSG_1_LW_0.txt", "V2",
"HKU47_PSG_1_LW_1.txt", "V2", "HKU47_PSG_1_LW_2.txt", "V2", "HKU47_PSG_1_LW_3.txt"
), row.names = c(NA, -9L), class = c("data.table", "data.frame"
), .internal.selfref = <pointer: 0x0000000000100788>)
재현 가능한 예가 도움이 될 것입니다. – MichaelChirico
'data.table'이 필요하고'matrix'가 필요하지 않습니까? – MichaelChirico
맞아요, 질문을 편집했습니다. – Danilo