example code:
df <- data.frame(datetime = c("2023-04-17 13:20", "2023-04-19 16:13", "2023-04-19 16:46", "2023-04-18 09:23"))
print(paste("The following dates are present in the datetime column: ",
unique(df$datetime), sep = ""))
output I get:
[1] "The following dates are present in the datetime column: 2023-04-17 13:20"
[2] "The following dates are present in the datetime column: 2023-04-19 16:13"
[3] "The following dates are present in the datetime column: 2023-04-19 16:46"
[4] "The following dates are present in the datetime column: 2023-04-18 09:23"
Output I desire:
"The following dates are present in the datetime column: 2023-04-17 13:20, 2023-04-19 16:13, 2023-04-19 16:46, 2023-04-18 09:23"
I tried to create a vector of c(unique(df$datetime)), but that did not help either. Does anyone know a nice way of solving this?
>Solution :
you can "double" paste:
print(paste("The following dates are present in the datetime column: ",
paste(unique(df$datetime),collapse=", "), sep = ""))
[1] "The following dates are present in the datetime column: 2023-04-17 13:20, 2023-04-19 16:13, 2023-04-19 16:46, 2023-04-18 09:23"