全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
7547 5
2011-06-01
现在手头上有一个数据样本,共3650000个数据,想将其分割成100个样本文件,分别命名为x1.txt, x2.txt, x3.txt……其中x1.txt由第1~36500个数据组成;x2.txt由第36501~73000个数据组成,依此类推。觉得R处理这个问题应该挺简单的,不过编程过程中还是遇到了问题。程序代码如下:
for (i in 1:100)
{
j=(i-1)*36500+1
k=i*36500
for(l in j:k)
{
y[[l]]=x[[l]]
}
file=paste("y",i,".txt",sep="")
write.table(y,file,append=FALSE,sep="                 ")
}

输出结果没按照我事先设想的输出,不知道是什么原因?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2011-6-1 17:22:10
Something's wrong with the inner loop. In your script, y will be eventually assigned the same as x. I assume the results will be the first file has the first 1% of the data, the second has the first 2%,...

Actually you may not need the inner loop at all. Consider the following code:

复制代码
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-6-1 17:44:11
Thank you so much for your advice~~I will try your code on my computer
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-6-1 20:56:35
经检验 您提供的代码错误:
错误于x[[j:k]] : 最多只能选择一个元素。。。

应该将x[[j:k]] 改为x[j:k],这样就能达到目的了。
Thank you all the same:)
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-6-10 13:54:58
在write里面用paste可以实现
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2011-6-10 17:57:24
file=paste("data", i,"txt")
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群