这个问题与标题相似的帖子有关(用相邻的值替换R向量中的NA)。我想扫描数据框中的一列,并用相邻单元格中的值替换NA。在上述文章中,解决方案是不使用相邻向量(例如,数据矩阵中的相邻元素)的值替换NA,而是有条件地替换固定值。以下是我的问题的可复制示例:UNIT <- c(NA,NA, 200, 200, 200, 200, 200, 300, 300, 300,300)STATUS <-c('ACTIVE','INACTIVE','ACTIVE','ACTIVE','INACTIVE','ACTIVE','INACTIVE','ACTIVE','ACTIVE', 'ACTIVE','INACTIVE') TERMINATED <- c('1999-07-06' , '2008-12-05' , '2000-08-18' , '2000-08-18' ,'2000-08-18' ,'2008-08-18', '2008-08-18','2006-09-19','2006-09-19' ,'2006-09-19' ,'1999-03-15') START <- c('2007-04-23','2008-12-06','2004-06-01','2007-02-01','2008-04-19','2010-11-29','2010-12-30', '2007-10-29','2008-02-05','2008-06-30','2009-02-07')STOP <- c('2008-12-05','4712-12-31','2007-01-31','2008-04-18','2010-11-28','2010-12-29','4712-12-31', '2008-02-04','2008-06-29','2009-02-06','4712-12-31')这个问题与标题相似的帖子有关(用相邻的值替换R向量中的NA)。我想扫描数据框中的一列,并用相邻单元格中的值替换NA。在上述文章中,解决方案是不使用相邻向量(例如,数据矩阵中的相邻元素)的值替换NA,而是有条件地替换固定值。以下是我的问题的可复制示例:UNIT <- c(NA,NA, 200, 200, 200, 200, 200, 300, 300, 300,300)STATUS <-c('ACTIVE','INACTIVE','ACTIVE','ACTIVE','INACTIVE','ACTIVE','INACTIVE','ACTIVE','ACTIVE', 'ACTIVE','INACTIVE') TERMINATED <- c('1999-07-06' , '2008-12-05' , '2000-08-18' , '2000-08-18' ,'2000-08-18' ,'2008-08-18', '2008-08-18','2006-09-19','2006-09-19' ,'2006-09-19' ,'1999-03-15') START <- c('2007-04-23','2008-12-06','2004-06-01','2007-02-01','2008-04-19','2010-11-29','2010-12-30', '2007-10-29','2008-02-05','2008-06-30','2009-02-07')STOP <- c('2008-12-05','4712-12-31','2007-01-31','2008-04-18','2010-11-28','2010-12-29','4712-12-31', '2008-02-04','2008-06-29','2009-02-06','4712-12-31')测试<-data.frame(UNIT,STATUS,TERMINATED,START,STOP)测试
3 回答
- 3 回答
- 0 关注
- 412 浏览
添加回答
举报
0/150
提交
取消