ritm
1
I have a single column in a dataframe in R which has few values such as below:
2 1 NDUyMg== Mon Jul 01 10:18:13 2019
2 1 NDUyMg== Tue Jul 02 11:34:16 2019
How do i separate them into multiple columns so that the output is something like below:
ID1 ID2 License Day Date Time
2 1 NDUyMg== Mon 01-Jul-2019 10:18:13
2 1 NDUyMg== Tue 02-Jul-2019 11:34:16
The easiest way is to split the column first using separate() and " " as separator and then combine the date back with mutate().
library(tidyverse)
df = data.frame("Col1" = c("2 1 NDUyMg== Mon Jul 01 10:18:13 2019",
"2 1 NDUyMg== Tue Jul 02 11:34:16 2019"))
df_sorted = df %>%
separate(Col1, into = c("ID1", "ID2", "License",
"Day", "mon", "date_day",
"Time", "year"),
sep =" ") %>%
mutate(Date = paste(date_day, mon, year, sep="-")) %>%
select(ID1, ID2, License, Date, Time)
df_sorted
ID1 ID2 License Date Time
1 2 1 NDUyMg== 01-Jul-2019 10:18:13
2 2 1 NDUyMg== 02-Jul-2019 11:34:16
I'd also recommend following this up with a converting the date and/time to a date format using the lubridate
package
system
Closed
4
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.