datetime - Converting R time column to specific strings -
I have a column that r
represents the time in a data frame when I say something like strings on the column;
& gt; Str (df2 $ time) factor w / 1441 level "", "00:01", "00:02", "00: 03", ..: 1086 10 9 11 11 and so on
The thing is that I want to convert this column to string type as if the time is less than 12:00, then it should be modified in the string "Mooring" if time is 12:00 and 6:00 , Then it is "daylight" and so on.
The first step I thought was to convert this vector to the data type column on the type of column, so I used the Cron function.
I have typed the following command,
& gt; Df2 $ time & lt; -chron (times = df2 $ time, format = c ('h: m')) Error in convert.times (times., Fmt): format h: m may be incorrect Additionally: Warning message: is.na (Outside $ s): is.na () non-applicable to "list" (vector) type "NULL"
I guess I should add another parameter to the format So I tried the following:
df2 $ time & lt; -chron (time = df2 $ time, format = c ('h: m: s'))
but still got the same error
I know This is just the first step, is my suggestion wrong? Can someone suggest me how to convert data cells in the morning, evening, night etc at these times?
Any help is greatly appreciated.
Chrome "times"
square and cut
Use:
Library (cron) # data copyable form df2 & lt; - data.frame (times = c ("00:01", "12:02", "19: 3")) df2 $ times & lt; - Bars (Paste 0 (DF 2 $ Times, ": 00" C) (0, 12, 18, 24) / 24 # are the inner parts of a circle labels, and (lt; -c ("morning", "daylight" , "Evening") df2 $ ind and lieutenant; - cut (df2 $ times, breaks, labels, include.love = TRUE)
which gives:
next time you copy your data Provide in a presentable form.
Revised Minor simplification and fixed Typo.
Comments
Post a Comment