英文:
print unique values of a column next to a string sentence [using paste()]
问题
您想要的输出是:
"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"
以下是代码部分的翻译:
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 = ""))
希望这对您有所帮助。如果您需要进一步的帮助,请随时提问。
英文:
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?
答案1
得分: 2
你可以“双重”粘贴:
print(paste("以下日期出现在日期时间列中:",
paste(unique(df$datetime), collapse=", "), sep = ""))
[1] "以下日期出现在日期时间列中:2023-04-17 13:20, 2023-04-19 16:13, 2023-04-19 16:46, 2023-04-18 09:23"
英文:
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"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论