如何在R中生成类似于”1.0 2.0 3.0 4.0 5.0 5.1 5.2 5.3 5.4 5.5″的输出?

huangapple go评论63阅读模式
英文:

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

huangapple
  • 本文由 发表于 2023年5月8日 00:29:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/76195072.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定