如何使用切割r划分向量?

发布于 2025-01-29 11:56:24 字数 209 浏览 1 评论 0原文

我听说我应该使用r中的剪切功能将数据分为相等的部分,但是它似乎并不像

   which(cut(1:1000,3)==1)

我当前的解决方案那样容易,

t<-cut(1:1000,3)
which(match(t,levels(t))==1)

我认为这是最好的解决方案。

I heard I'm supposed to use the cut function in R to divide data into equal parts, but it doesn't seem to be as easy as

   which(cut(1:1000,3)==1)

My current solution is

t<-cut(1:1000,3)
which(match(t,levels(t))==1)

I don't believe this to be the best solution.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

〆凄凉。 2025-02-05 11:56:24
s <- 1:1000
t <- split(s, cut(s, 3))

将为您提供三个组的列表,每个组具有1/3的顺序。然后,您将使用t [1]来获取第一组。

s <- 1:1000
t <- split(s, cut(s, 3))

will give you a list with three groups, each having 1/3 of the sequence. Then you would use t[1] to get the first group, for instance.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文