R 如何将集合项与随机元素混合
我想在一定范围内生成一组随机坐标,然后以小时、分钟、秒(例如39°50'30“N)的形式打印结果 到目前为止,我所拥有的:R 如何将集合项与随机元素混合,r,R,我想在一定范围内生成一组随机坐标,然后以小时、分钟、秒(例如39°50'30“N)的形式打印结果 到目前为止,我所拥有的: #Set the seed for random number generation set.seed(0112) #Define the integers for each part of the coordinates h <- sample.int(38:41, 1) m <- sample.int(52, 1) s <- sample.int(3
#Set the seed for random number generation
set.seed(0112)
#Define the integers for each part of the coordinates
h <- sample.int(38:41, 1)
m <- sample.int(52, 1)
s <- sample.int(31, 1)
#Print the results
print(paste("h","°","m","'","s", "", "N"), quote = FALSE)
如何使生成的数字显示在打印结果中,而不是显示给整数的名称?将它们从粘贴中的引号(“”
)中删除
paste(h,"°",m,"'",s, "", "N")
#[1] "15 ° 48 ' 31 N"
print
中的quote
的目的不同于?print
quote-逻辑,指示字符串是否应使用周围的引号打印
例如,见
print(paste(h,"°",m,"'",s, "", "N"), quote = TRUE)
#[1] "15 ° 48 ' 31 N"
print(paste(h,"°",m,"'",s, "", "N"), quote = FALSE)
#[1] 15 ° 48 ' 31 N
请注意,在第一种情况下,而不是在第二种情况下,输出是如何被引号(“
)包围的 多谢各位<代码>打印(粘贴(h,“,”m,“,”s,“,”N”),引号=FALSE)
提供了我所需要的。单引号强制双引号出现在秒旁边。知道如何删除整数和度符号之间的空格吗?@TravisHamon使用paste0
打印(粘贴0(h,“,”m,“,”s,“,”N),引号=FALSE)工作起来很有魅力。又比你强
print(paste(h,"°",m,"'",s, "", "N"), quote = TRUE)
#[1] "15 ° 48 ' 31 N"
print(paste(h,"°",m,"'",s, "", "N"), quote = FALSE)
#[1] 15 ° 48 ' 31 N