如何使用"for循环"和"write.csv"同时? [英] how to use "for loop" and "write.csv" at the same time?

查看:319
本文介绍了如何使用"for循环"和"write.csv"同时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组.它具有纬度,经度,时间和价值.时间从1到300.这是时间= 1的数组的一部分.

I have an array. It has lat,lon,time,and value. Time starts from 1 to 300. Here is part of array for time=1.

myarray[,,1]
     lon                        
    lat -124.5  -123.5  -122.5  -121.5  -120.5  -119.5  -118.5
31.5    0   0   0   0   0   0
32.5    0   0   0   0   0   0
33.5    0   0   0   0   0   0
34.5    0   0   0   0   0   0
35.5    0   0   0   0   0   0
36.5    0   0   0   768.1   0   126.2
37.5    0   0   0.2 0   811 212.1
38.5    0   0   3055    0   243.9   243.7
39.5    0   0   1.5 0.1 3   0
40.5    0.1 16.8    4.3 0.5 2.1 0
41.5    0.2 398.6   0.4 1.2 1.6 0
42.5    0   0.1 0.9 0.1 0.7 0

我想同时使用"write.csv"和"for循环"从每个时间步(1到300)从数组中读取数据,并将它们存储在单独的.csv文件中,这些文件具有"i"作为指数.我使用了此命令,但似乎不起作用:

I want to use "write.csv" and "for loop" at the same time to read the data from array for each time step (1 to 300) and store them in individual .csv files which has "i" as index. I used this command but it seems that it doesn't work:

for (i in 1:300)    write.csv(myarray[,,i],"myarray.i.csv")

推荐答案

有多种解决方法:

paste('myarray', i, 'csv', sep = '.')

或:

sprintf('myarray.%d.csv', i)

我喜欢最后一个.

这篇关于如何使用"for循环"和"write.csv"同时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆