英文:
How do I generate an output like "1.0 2.0 3.0 4.0 5.0 5.1 5.2 5.3 5.4 5.5" in R?
问题
我们应该学习seq()
、:
和rep()
命令,但我可能漏掉了一些东西。我无法理解如何在序列中间更改输出间隔。
就像标题所说,期望的输出是1.0 2.0 3.0 4.0 5.0 5.1 5.2 5.3 5.4 5.5
。
我尝试过像这样链接命令,但结果是以下输出:
1:5 ; seq(from = 5.1, to = 5.5, by = 0.1)
但它导致了以下输出:
[1] 1, 2, 3, 4, 5
[1] 5.1, 5.2, 5.3, 5.4, 5.5
我还尝试将这两个命令的输出分配给变量,但我不太知道如何将它们组合在一起而不将值相加。
非常感谢!
英文:
We are supposed to learn the seq()
, :
and rep()
command with this exercise but I must have missed something. I cant wrap my head around how you can change the output intervals of a sequence mid sequence like that.
Like the title says the desired output is 1.0 2.0 3.0 4.0 5.0 5.1 5.2 5.3 5.4 5.5
.
I've tried chaining commands like this but it resulted in the below output:
1:5 ; seq(from = 5.1, to = 5.5, by = 0.1)
But it resulted in this output
[1] 1, 2, 3, 4, 5
[1] 5.1, 5.2, 5.3, 5.4, 5.5
I also tried assigning the output of those two commands to variables but I don't quite know how to combine them without adding the values together.
Many thanks in advance.
答案1
得分: 1
你可以执行以下代码:
c(1.0:5.0, seq(5.1,5.5,.1))
输出
[1] 1.0 2.0 3.0 4.0 5.0 5.1 5.2 5.3 5.4 5.5
英文:
You could do
c(1.0:5.0, seq(5.1,5.5,.1))
output
[1] 1.0 2.0 3.0 4.0 5.0 5.1 5.2 5.3 5.4 5.5
答案2
得分: 1
我猜你的代码应该是c(seq(1,5,1), seq(5.1, 5.5,0.1))
,然后你将得到一个包含所需输出的单一向量。
英文:
I guess your code should be c(seq(1,5,1), seq(5.1, 5.5,0.1))
then you have a single vector with the desired output
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论