Introduction to Repeating Things in R: Looping by Index

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

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 7 ай бұрын
Excellent explanation!
@weecology
@weecology 7 ай бұрын
Thanks!
@AnkeetKumar
@AnkeetKumar Жыл бұрын
Amazing video...
@weecology
@weecology Жыл бұрын
Thanks!
@marcomora4
@marcomora4 10 ай бұрын
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!
@larissacury7714
@larissacury7714 2 жыл бұрын
Thank you VERY much!
@weecology
@weecology 2 жыл бұрын
Glad it's helpful!
@asadkhanbb
@asadkhanbb Жыл бұрын
Thank you
@weecology
@weecology Жыл бұрын
You're welcome!
@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
@韦德-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?
Introduction to Repeating Things in R: Basic For Loops
9:45
weecology
Рет қаралды 1,4 М.
Интересно, какой он был в молодости
01:00
БЕЗУМНЫЙ СПОРТ
Рет қаралды 3,4 МЛН
Мясо вегана? 🧐 @Whatthefshow
01:01
История одного вокалиста
Рет қаралды 7 МЛН
Do you love Blackpink?🖤🩷
00:23
Karina
Рет қаралды 25 МЛН
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 10 МЛН
Indexing and looping over lists in R, a tutorial (CC174)
19:59
Riffomonas Project
Рет қаралды 5 М.
Introduction to Repeating Things in R: Looping Over Files
10:22
Bar charts and Histograms using ggplot in R
18:22
R Programming 101
Рет қаралды 70 М.
Introduction to Repeating Things in R: Looping Using Functions
9:22
SQL Databases For dplyr Users: Introduction
10:17
weecology
Рет қаралды 3,3 М.
Combine Excel Files Fast using R Tidyverse
19:32
Jonathan Ng (Data Pro)
Рет қаралды 24 М.
t-test and interpreting p values using R Programming
26:53
R Programming 101
Рет қаралды 90 М.
Try This if You Don’t Like Python’s Exception Handling
21:27
Интересно, какой он был в молодости
01:00
БЕЗУМНЫЙ СПОРТ
Рет қаралды 3,4 МЛН