- 主题:请教重新生成变量的问题(R语言)
- 麻烦请帮我看一下,数据是随访数据,我想新生成一个时间变量,表示末次随访时间。Freq表示随访次数,报告日期n表示第几次随访的时间。以下是我写的程序,总是出错,是不是因为赋值不是一个固定值的原因?请教大家,应该怎么写这个命令?多谢啦!
 temp$time<- within(temp,{
 time<-as.POSIXct(报告日期)
 time[Freq==2]<-as.POSIXct(报告日期2)
 time[Freq==3]<-as.POSIXct(报告日期3)
 time[Freq==4]<-as.POSIXct(报告日期4)
 time[Freq==5]<-as.POSIXct(报告日期5)
 time[Freq==6]<-as.POSIXct(报告日期6)
 time[Freq==7]<-as.POSIXct(报告日期7)
 })
 
 结果出错信息:
 Warning messages:
 1: In NextMethod(.Generic) :
 number of items to replace is not a multiple of replacement length
 2: In NextMethod(.Generic) :
 number of items to replace is not a multiple of replacement length
 3: In NextMethod(.Generic) :
 number of items to replace is not a multiple of replacement length
 4: In NextMethod(.Generic) :
 number of items to replace is not a multiple of replacement length
 5: In NextMethod(.Generic) :
 number of items to replace is not a multiple of replacement length
 --
 FROM 210.75.207.*
 
- 【 在 sxr (月儿) 的大作中提到: 】
 : 标  题: 请教重新生成变量的问题(R语言)
 : 发信站: 水木社区 (Thu Oct 21 14:59:35 2021), 站内
 :
 : 麻烦请帮我看一下,数据是随访数据,我想新生成一个时间变量,表示末次随访时间。Freq表示随访次数,报告日期n表示第几次随访的时间。以下是我写的程序,总是出错,是不是因为赋值不是一个固定值的原因?请教大家,应该怎么写这个命令?多谢啦!
 : temp$time<- within(temp,{
 :                    time<-as.POSIXct(报告日期)
 :                    time[Freq==2]<-as.POSIXct(报告日期2)
 :                    time[Freq==3]<-as.POSIXct(报告日期3)
 :                    time[Freq==4]<-as.POSIXct(报告日期4)
 :                    time[Freq==5]<-as.POSIXct(报告日期5)
 :                    time[Freq==6]<-as.POSIXct(报告日期6)
 :                    time[Freq==7]<-as.POSIXct(报告日期7)
 :                    })
 :
 : 结果出错信息:
 : Warning messages:
 : 1: In NextMethod(.Generic) :
 :   number of items to replace is not a multiple of replacement length
 : 2: In NextMethod(.Generic) :
 :   number of items to replace is not a multiple of replacement length
 : 3: In NextMethod(.Generic) :
 :   number of items to replace is not a multiple of replacement length
 : 4: In NextMethod(.Generic) :
 :   number of items to replace is not a multiple of replacement length
 : 5: In NextMethod(.Generic) :
 :   number of items to replace is not a multiple of replacement length
 :
 
 这个信息大概是说 time[...] 的长度与 as.POSIXct(...) 长度不一样
 --
 FROM 59.172.4.*
 
- 应该怎么修改呢?
 
 【 在 snoopyzhao @ [DataScience] 的大作中提到: 】
 :
 : 【 在 sxr (月儿) 的大作中提到: 】
 : : 标 题: 请教重新生成变量的问题(R语言)
 : : 发信站: 水木社区 (Thu Oct 21 14:59:35 2021), 站内
 : :
 
 #发自zSMTH@ELZ-AN00
 --
 FROM 120.245.66.*