I want to combine two columns in the data frame with R to create a new column.

Asked 2 years ago, Updated 2 years ago, 40 views


To create a new column by combining two columns in a data frame with R. https://www.trifields.jp/how-to-add-multiple-joined-columns-by-specifying-multiple-columns-as-strings-in-dplyr-package-in-r-2812

with reference to
data2<-data%>%mute(NewCol=paste(!!!rlang::syms(c("var1", "var2")), sep=""))

Yes, but

Error in UseMethod("mute_"): 
  no applicable method for 'mute_' applied to an object of class "character"

It will be

By the way, var1 is yymmdd and var2 is hms converted to character.
(Because the first Date and hms types also failed.)

Also, it is okay to simply combine strings, but is there a type that can express the date, time, and seconds of the year at once?
If you look into it,

strptime(datetime, "%Y%m%d%H%M%S")

There seems to be something like this, but it seems to be different from the type provided by default just by specifying the format yourself...

r

2022-09-30 21:33

1 Answers

Is there a type that can express the date, time, and seconds of the year at once?

If you use the ymd_hms function of the lubridate package to substitute a string such as 2018-2-24 15:30:15, it will go.
As soon as I asked the question, I found the page below.Sorry for the self-answer.

https://kazutan.github.io/SappoRoR8/01-lubridate.html

I am not sure about the cause of the error, so I would appreciate it if you could let me know.


2022-09-30 21:33

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.