我有一个XLS文件与这个数据帧,我需要更新它
V1 V2 V3 V4 V5 V6 V7 V8
1 1 EFNB2 EFNB2 EFNB2 72 0.667 0.05980 YES
2 2 AOC2 AOC2 AOC2 108 0.609 0.13000 YES
3 3 FOS FOS FOS 142 0.554 0.19300 YES
4 4 CCNE1 CCNE1 CCNE1 167 0.530 0.25700 YES
5 5 CBX4 CBX4 CBX4 275 0.448 0.26700 YES
6 6 CRY1 CRY1 CRY1 343 0.400 0.29000 YES
7 7 TNFAIP6 TNFAIP6 TNFAIP6 600 0.194 0.18500 NO
8 8 SSX3 SSX3 SSX3 641 0.171 0.18900 NO
9 9 WNT2 WNT2 WNT2 1211 -0.173 -0.08030 NO
10 10 FGF18 FGF18 FGF18 1296 -0.225 -0.09130 NO
11 11 PIM2 PIM2 PIM2 1386 -0.273 -0.09780 NO
我只对V7和V8感兴趣。假设我在V7值上应用条件。如果应用,我会将它旁边的单元格(V8)从NO更新为YES,从此单元格开始到V8的最后一个单元格。附:如果V8 =是,请保持不变。
实施例: df(9,V7)= -0.08030,满足条件。 然后我应该访问该表并更新V8
V1 V2 V3 V4 V5 V6 V7 V8
1 1 EFNB2 EFNB2 EFNB2 72 0.667 0.05980 YES
2 2 AOC2 AOC2 AOC2 108 0.609 0.13000 YES
3 3 FOS FOS FOS 142 0.554 0.19300 YES
4 4 CCNE1 CCNE1 CCNE1 167 0.530 0.25700 YES
5 5 CBX4 CBX4 CBX4 275 0.448 0.26700 YES
6 6 CRY1 CRY1 CRY1 343 0.400 0.29000 YES
7 7 TNFAIP6 TNFAIP6 TNFAIP6 600 0.194 0.18500 NO
8 8 SSX3 SSX3 SSX3 641 0.171 0.18900 NO
9 9 WNT2 WNT2 WNT2 1211 -0.173 -0.08030 YES
10 10 FGF18 FGF18 FGF18 1296 -0.225 -0.09130 YES
11 11 PIM2 PIM2 PIM2 1386 -0.273 -0.09780 YES
更新 这是它应该满足的条件
#Checking the change of signs of the 1st derivative of V7 (unlins)
check_sign <- which(diff(sign(unlins))==-2|diff(sign(unlins))==2 ,1)
#assigning integrated values of unlins (V7)
V7_values <- df1$V7[check_sign] #return values of V7
>> V7_values
[1] 0.2570 -0.1670 -0.0419
我尝试使用这个建议的代码,
df1$V8[df1$V8 == 'NO' & df1$V7 %in% V7_values] <- 'YES'
>>df1
V1 V2 V3 V4 V5 V6 V7 V8
1 1 EFNB2 EFNB2 EFNB2 72 0.667 0.05980 YES
2 2 AOC2 AOC2 AOC2 108 0.609 0.13000 YES
3 3 FOS FOS FOS 142 0.554 0.19300 YES
4 4 CCNE1 CCNE1 CCNE1 167 0.530 0.25700 YES
5 5 CBX4 CBX4 CBX4 275 0.448 0.26700 YES
6 6 CRY1 CRY1 CRY1 343 0.400 0.29000 YES
7 7 TNFAIP6 TNFAIP6 TNFAIP6 600 0.194 0.18500 NO
8 8 SSX3 SSX3 SSX3 641 0.171 0.18900 NO
9 9 WNT2 WNT2 WNT2 1211 -0.173 -0.08030 NO
10 10 FGF18 FGF18 FGF18 1296 -0.225 -0.09130 NO
11 11 PIM2 PIM2 PIM2 1386 -0.273 -0.09780 NO
12 12 PLCL1 PLCL1 PLCL1 1636 -0.415 -0.16700 YES
13 13 MX2 MX2 MX2 1676 -0.437 -0.12400 NO
14 14 ABCA6 ABCA6 ABCA6 1720 -0.457 -0.07980 NO
15 15 HSPA12A HSPA12A HSPA12A 1788 -0.501 -0.04190 YES
16 16 TNFSF10 TNFSF10 TNFSF10 1944 -0.855 0.00155 NO
但它仅更新了V8的条件,仅满足V7的条件(12&amp; 15)。虽然我需要它从12开始更新并延伸到表的末尾。
更新 最后,这工作
df1$V8[which(df1$V8 == 'NO' & df1$V7 %in% V7_values)[1]: length(df1$V8)] <- 'YES'