Introduction to Repeating Things in R: Looping by Index

  Рет қаралды 2,792

weecology

weecology

Күн бұрын

Пікірлер: 16
@koterm
@koterm 3 жыл бұрын
Thank you Ethan for this very clear explanation!
@weecology
@weecology 3 жыл бұрын
Your welcome! Glad it was useful.
@fernanda.vallejos
@fernanda.vallejos 8 ай бұрын
Excellent explanation!
@weecology
@weecology 8 ай бұрын
Thanks!
@AnkeetKumar
@AnkeetKumar 2 жыл бұрын
Amazing video...
@weecology
@weecology 2 жыл бұрын
Thanks!
@marcomora4
@marcomora4 11 ай бұрын
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!
@韦德-n8d
@韦德-n8d 2 жыл бұрын
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?
@weecology
@weecology 2 жыл бұрын
Can you include the code here to help me understand what you're trying to do?
@larissacury7714
@larissacury7714 2 жыл бұрын
Thank you VERY much!
@weecology
@weecology 2 жыл бұрын
Glad it's helpful!
@ahsanullahkhan5873
@ahsanullahkhan5873 2 жыл бұрын
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 .
@weecology
@weecology 2 жыл бұрын
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.
@ahsanullahkhan5873
@ahsanullahkhan5873 2 жыл бұрын
@@weecology thank you so much , its working like magicccc
@asadkhanbb
@asadkhanbb Жыл бұрын
Thank you
@weecology
@weecology Жыл бұрын
You're welcome!
Introduction to Repeating Things in R: Basic For Loops
9:45
weecology
Рет қаралды 1,4 М.
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
Indexing and looping over lists in R, a tutorial (CC174)
19:59
Riffomonas Project
Рет қаралды 5 М.
Loops using R programming
13:37
R Programming 101
Рет қаралды 17 М.
Fast Inverse Square Root - A Quake III Algorithm
20:08
Nemean
Рет қаралды 5 МЛН
What P vs NP is actually about
17:58
Polylog
Рет қаралды 146 М.
Introduction to Repeating Things in R: Looping Using Functions
9:22
How to read Haskell code (in 7 minutes)
6:51
peppidesu
Рет қаралды 77 М.
How AI Reasons | From AlphaGo to ChatGPT
17:24
Art of the Problem
Рет қаралды 76 М.
For Loops in R
11:34
Richard Webster
Рет қаралды 210 М.
Where Does Bad Code Come From?
42:21
Molly Rocket
Рет қаралды 210 М.
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН