Good morning everyone, I am currently using the code written by Antonio Olinto Avila-da-Silva on this link: https://oceancolor.gsfc.nasa.gov/forum/oceancolor/topic_show.pl?tid=5954 It allows me to extract data of type sst/chlor_a from nc file. It uses a loop to create an excel file with all the data. Unfortunately, I noticed that the function only takes the first data file in the loop. Thus, I find myself with 20 times the same data in a row in my excel file. Does anyone have a solution to make this loop work properly?
Asked
Active
Viewed 121 times
0
-
2Welcome to SO! It'll be easier for people to assist if the question is reproducible. Here's a guide [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with tips and tricks. Since SO will live on forever, it's important to make questions as self-contained as possible. The URL above could go away on a moment's notice and leave this question orphaned...having said that, I skimmed the script and identified what I think the problem is, but can't say with certainty since this isn't reproducible. Answer below. Good luck! – Chase May 03 '20 at 13:40
1 Answers
2
I would first check out that these two lines contain all the files you are expecting:
(f <- list.files(".", pattern="*.L3m_MO_SST_sst_9km.nc",full.names=F))
(lf<-length(f))
And then there's a bug in the for-loop. This line:
data<-nc_open(f)
Needs to reference the iterator i
, so change it to something like this:
data<-nc_open(f[[i]])
It appears both scripts have this same bug.

Chase
- 67,710
- 18
- 144
- 161