Open cahartin opened 8 years ago
`
files= list.files(pattern='*.nc',full.names=TRUE) global_temp=list()
for(i in seq_along(files)) { print (files[i])
nc = nc_open(files[i])
global_temp [[i]] <- data.frame(temp = ncvar_get(nc,'tas'), year= round((ncvar_get(nc,'time')/1e4), digits=0), file= basename(files[i])) nc_close(nc) }
#Add the values from each file to a single data.frame df<-bind_rows(globaltemp) %>% separate(file, into = c("var", "model","scenario", "ens", "yrs", "regrid"), sep = "")
#Add
write.table(df, "C:/Users/hart428/Documents/glb_temp_KC/glb_mean_esmrcp85.csv", sep =",", row.names=F) `
`
Open all files
files= list.files(pattern='*.nc',full.names=TRUE) global_temp=list()
Loop over files
for(i in seq_along(files)) { print (files[i])
nc = nc_open(files[i])
Read the whole nc file and pull out variables of interest
global_temp [[i]] <- data.frame(temp = ncvar_get(nc,'tas'), year= round((ncvar_get(nc,'time')/1e4), digits=0), file= basename(files[i])) nc_close(nc) }
#Add
the values from each file to a single data.frame df<-bind_rows(globaltemp) %>% separate(file, into = c("var", "model","scenario", "ens", "yrs", "regrid"), sep = "")write.table(df, "C:/Users/hart428/Documents/glb_temp_KC/glb_mean_esmrcp85.csv", sep =",", row.names=F) `