微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

通过引用另一个数据框更新数据框列值

如何解决通过引用另一个数据框更新数据框列值

我的第一个数据框 (df) 包含 Entrydate 和 ExitDate 列。另一个数据框 (n1) 包含所有交易日期。我需要第一个数据帧中的一个新列,计算为从第二个数据帧计算的天数。我如何为 df 的每一行调用这个 dayCount 函数。当我尝试使用 mapply 时,我无法将 n1 作为参数传递。

dayCount <- function (startDate,endDate,n1) {
 return (nrow(subset(n1,Date >= startDate & Date <= endDate)))
}

df<- structure(list(EntryDate = structure(c(11355,11418,11436,11449,11520,11523,11548,11620,11768,11773),class = "Date"),ExitDate = structure(c(11360,11422,11438,11457,11522,11526,11554,11625,11772,11778
),class = "Date")),row.names = c(22L,65L,76L,84L,135L,138L,155L,204L,305L,307L),class = "data.frame")

n1<- structure(c(11354,11355,11358,11359,11360,11361,11362,11365,11366,11367,11368,11369,11372,11373,11374,11375,11376,11379,11380,11381,11382,11383,11386,11388,11389,11390,11393,11394,11395,11396,11397,11400,11401,11402,11403,11404,11407,11408,11409,11410,11411,11414,11415,11416,11421,11423,11424,11428,11429,11430,11431,11432,11435,11437,11439,11442,11444,11445,11446,11450,11451,11452,11453,11456,11458,11459,11460,11463,11464,11465,11466,11467,11470,11471,11472,11473,11474,11477,11478,11479,11480,11481,11484,11485,11486,11487,11488,11491,11492,11493,11494,11495,11498,11499,11500,11501,11502,11505,11506,11507,11508,11509,11512,11513,11514,11515,11516,11519,11521,11527,11528,11529,11530,11533,11534,11535,11536,11537,11540,11541,11542,11543,11544,11547,11550,11551,11555,11557,11558,11561,11562,11563,11564,11565,11568,11569,11570,11571,11572,11575,11576,11577,11578,11579,11582,11583,11584,11585,11586,11589,11590,11591,11592,11593,11596,11598,11599,11600,11603,11604,11605,11606,11607,11610,11611,11612,11613,11614,11617,11618,11619,11624,11626,11627,11628,11631,11632,11633,11634,11635,11638,11639,11640,11641,11645,11646,11647,11648,11649,11652,11653,11654,11655,11659,11660,11661,11662,11663,11666,11667,11668,11669,11670,11674,11675,11676,11677,11680,11682,11683,11684,11687,11688,11689,11690,11691,11694,11695,11696,11697,11698,11701,11702,11703,11704,11705,11708,11709,11710,11711,11712,11715,11716,11717,11718,11719,11722,11723,11724,11725,11726,11729,11730,11731,11732,11733,11736,11737,11738,11739,11740,11743,11744,11745,11746,11747,11750,11751,11752,11753,11754,11757,11758,11759,11760,11761,11764,11765,11766,11767,11773,11774,11778),class = "Date")

解决方法

您可以使用 #1: 1 The book of the generation of Jesus Christ,the son of David,the son of Abraham. #2: 2 Abraham begat Isaac; and Isaac begat Jacob; and Jacob begat Judas and his brethren; #3: 3 And Judas begat Phares and Zara of Thamar; and Phares begat Esrom; and Esrom begat Aram; #4: 4 And Aram begat Aminadab; and Aminadab begat Naasson; and Naasson begat Salmon; #5: 5 And Salmon begat Booz of Rachab; and Booz begat Obed of Ruth; and Obed begat Jesse; 计算 %in%n1 之间的 EntryDate 天数。

ExitDate

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。