如何解决如何在日期中使用ifelse
我在R中的日期格式为01/01/2000
我想创建一列,其类别将我的受试者分类为出生日期const DevList: React.FC = () => {
const [developers,setDevelopers] = useState<DevelopersData[]>([]);
const getDevelopers = useCallback(async () => {
await api.get("/developers").then((response) => {
setDevelopers(response.data);
});
},[setDevelopers]);
useEffect(() => {
getDevelopers();
},[getDevelopers]);
const onAddDeveloper = useCallback(
async (newDeveloper) => {
const newDevelopers = developers.concat([newDeveloper]);
setDevelopers(newDevelopers);
try {
await postNewDeveloperToAPI(newDeveloper); // Todo: Implement me
} catch (e) {
alert("Oops,Failed posting developer information...");
}
getDevelopers();
},[developers],);
return (
<>
<AddDeveloperForm onAddDeveloper={onAddDeveloper} />
<DeveloperList developers={developers} />
</>
);
};
之前或01/02/2001 ==1
之后。可以用02/02/2001 ==2
完成吗?
您将如何表达?
谢谢
解决方法
选项1:ifelse()
ifelse(as.Date(date,"%d/%m/%Y") < as.Date("2001-02-02"),1,2)
# [1] 1 2 2 2
选项2
2 - (as.Date(date,"%d/%m/%Y") < as.Date("2001-02-02"))
# [1] 1 2 2 2
选项3:findInterval()
findInterval(as.Date(date,"%d/%m/%Y"),as.Date("2001-02-02")) + 1
# [1] 1 2 2 2
数据
date <- c("01/02/2001","02/02/2001","03/02/2001","04/02/2001")
,
这取决于格式,您必须添加函数“ as.Date()
例如:
日期
adates = as.Date(日期,“%d-%m-%Y”)
ifelse(adates>预定日期(“ 01-02-2001”,“%d-%m-%Y”),1,0)
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。