如何解决如何使用 Lubridate 从 YYYY-MM-DD HH:MM:SS 格式创建新列“月”?
我正在尝试使用 lubridate 从以下格式创建一个仅包含月份的新列:
2020-01-01 00:00:00 yyyy-mm-dd hh:mm:ss
提前致谢。
weather4 %>%
-
mutate(Year = year(weather4$valid),
-
Month = month(weather4$valid),
-
Day = day(weather4$valid))
非常感谢您提前
解决方法
import React,{ useState } from 'react';
import { StyleSheet,Text,View,FlatList,Alert,Button } from 'react-native';
import Header from './components/header';
import Workouts from './components/workouts';
import AddWorkout from './components/addWorkout';
export default function App() {
const [workout,setWorkout] = useState(false);
const [workouts,setWorkouts] = useState([
{ name: 'Pushups',key: '1',sets: '3',reps: '20' },{ name: 'Test',key: '2',]);
const [currentWorkout,setCurrentWorkout] = useState(workouts[0]);
const [currentSets,setCurrentSets] = useState(3)
const [dummyWorkouts,setDummyWorkouts] = useState();
const pressHandler = (key) => {
setWorkouts((prevWorkouts) => {
return prevWorkouts.filter(workout => workout.key != key);
})
}
const submitHandler = (text) => {
if(text.length > 0){
if(text.length <= 40){
setWorkouts((workouts) => {
return [
{ name: text,key: Math.random().toString(),reps: '10',sets: '3' },...workouts
]
})
}else {Alert.alert('Whoops!',"You entered over 40 characters! Shorten it up a bit!",[{text: 'Close '}])}
}else {Alert.alert('Whoops!',"You haven't entered anything!",[{text: 'Close '}])}
}
if(workout == false){
return (
<View style={styles.container}>
<Header />
<View style={styles.WorkoutButton}>
<Button
title='START'
color='white'
onPress={()=>{
if(workouts.includes(workouts[0])){
setDummyWorkouts([...workouts])
setWorkout(true)
}else{Alert.alert('Whoops!',"No workouts detected!",[{text: 'Close '}])}
}}
/>
</View>
<View style={styles.content}>
<AddWorkout submitHandler={(val) => {submitHandler}}/>
<View style={styles.list}>
<FlatList
data={workouts}
renderItem={({ item }) => (
<Workouts item={item} pressHandler={pressHandler} />
)}
/>
</View>
</View>
</View>
);}else if (workout == true && workouts.includes(workouts[0])){
return(
<View style={styles.container}>
<Header />
<View style={styles.WorkoutButton}>
<Button
title='-'
color='white'
onPress={() => {
setCurrentSets(currentSets-1)
if(currentSets == 1){
if(dummyWorkouts.length > 1){
setCurrentWorkout(dummyWorkouts[1])
setCurrentSets(dummyWorkouts[1].sets)
var index = dummyWorkouts.indexOf(dummyWorkouts[0])
setDummyWorkouts(dummyWorkouts.splice(index,1)) //delete workout
}else{
setDummyWorkouts(workouts)
setCurrentWorkout(workouts[0])
setCurrentSets(workouts[0].sets)
setWorkout(false)
}
}
}}
/>
</View>
<View style={styles.WorkoutCard}>
<Text style={styles.Workout}>
{currentWorkout.name}
</Text>
<Text style={styles.Sets}>
Sets Left
{'\n'}
{currentSets}
</Text>
<Text style={styles.Reps}>
Reps
{'\n'}
{currentWorkout.reps}
</Text>
</View>
</View>
);}else{
setWorkout(false)
Alert.alert('Whoops!',[{text: 'Close '}])
}
}
//Style Sheet
const styles = StyleSheet.create({
container: {
flex: 1,backgroundColor: '#3B3B3B',},content: {
padding: 60,flex: 1,list: {
marginTop: 20,flex:1,text: {
color: 'white',WorkoutButton: {
backgroundColor: 'black',left: 140,bottom: 52,marginHorizontal: 150,borderRadius: 15,fontWeight: 'bold',WorkoutCard: {
backgroundColor: 'crimson',height: 600,width: 300,marginTop: 50,alignSelf: 'center',borderRadius: 50,Workout: {
fontSize: 50,fontWeight: '600',color: 'white',textAlign: 'center',Sets: {
fontSize: 50,fontWeight: '400',top: 30,Reps: {
fontSize: 40,top: 50,});```
在您的样本中充满了 NA。它有任何有效数据吗?
我怀疑你需要 year(weather4$valid) 你正在给它管道 weather4 所以你通常只需要 year(valid) ......
假设 valid 中有日期?
现在如果它...它也认为它是根据表格判断的字符,因此您需要将其更改为“日期”或日期时间。
所以我建议:
weather4$valid
您可能希望执行一次并通过管道传输结果...
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。