Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

print unique values of a column next to a string sentence [using paste()]

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

"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"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading