How can I create a data frame on each "i" itereation. For instance if I want to remove same column on each data frame, named data 01, data02, data03, etc etc. Or maybe for this task i-loop is not the best option?, Tank you in advande!
@larissacury77142 жыл бұрын
Thank you VERY much!
@weecology2 жыл бұрын
Glad it's helpful!
@asadkhanbb Жыл бұрын
Thank you
@weecology Жыл бұрын
You're welcome!
@ahsanullahkhan58732 жыл бұрын
Hi Sir , really well explained . I have a query ,So my input files are in .nc format and its name starts with "pr" so its easy to list/choose them with list.files(pattern="pr") . Station file is one constant file . Now what I want is a separate output file in a .csv format for each of my input file and the name of my output file preferably would be same as that of input files. The following script does the job well if i go with one input at a time, i wanna loop it T*T . I am Noob af at programming, started learning it recently as i need it . Hoping for a reply . Thank you so much . CODE : setwd("D:\\data\\pr") library (raster) ## load required library library(sp) ## load library library(ncdf4) station.data = read.csv("stations.csv", sep = ",", header =T) ## import station data.file lon.lat = station.data[,c(2,3)] ## extract data of all stations in station file for which point values are to be extractd lon.lat = SpatialPoints(lon.lat) ## lon.lat for further use lon.lat robject = brick(inputfile, varname = "pr")## import raster netcdf file from which point values are to be extractd dim(robject) ## check the dimensions of project vall = extract(robject , lon.lat, method = "simple" ) ## extract values vall = t(vall) write.csv(vall, file = "output_file.csv", fileEncoding = "macroman") } ## save output csv file containing extracted point values .
@weecology2 жыл бұрын
Glad it's useful! Start by taking a look at our video on looping over files to understand the basics: kzbin.info/www/bejne/al7YiJqeatB3icU In your case you want something like: data_files = list.files(pattern="pr") for (current_file in data_files) { station.data = read.csv(current_file, sep = ",", header = T) # The rest of your code write.csv(vall, file = paste("output_", current_file), fileEncoding = "macroman") } The paste() in the last line means that the output file will be named "output_" plus the name of the input file. If you just used current_file instead it would overwrite your input file.
@ahsanullahkhan58732 жыл бұрын
@@weecology thank you so much , its working like magicccc
@韦德-n8d2 жыл бұрын
Hello sir if i plus a mass to the right hand of the equation .and give a initial value of mass. Your method do not work . Can you help me?
@weecology2 жыл бұрын
Can you include the code here to help me understand what you're trying to do?