![using r to write res2dinv files using r to write res2dinv files](https://i.ytimg.com/vi/wiukzcedLws/maxresdefault.jpg)
#Using r to write res2dinv files code#
Here’s the code in it’s entirety, put together for ease of pasting. Temp_dataset <-read.table(file, header=TRUE, sep="\t") # if the merged dataset does exist, append to it # if the merged dataset doesn't exist, create itĭataset <- read.table(file, header=TRUE, sep="\t") If dataset doesn’t exist ( !exists is true), then we create it.The temporary dataframe is removed when we’re done with it using the rm(temp_dataset) command. If dataset already exists, then a temporary dataframe called temp_dataset is created and added to dataset.To provide the linearized raw resistivity data collected by the AGI SuperSting system in the RES2DINV format. This is done using the !exists conditional: These data were processed using AGIs EarthImager 2D software. When the script encounters the first file in the file_list, it creates the main dataframe to merge everything into (called dataset here). The final step is to iterate through the list of files in the current working directory and put them together to form a dataframe. save for writing any R objects, write.table for data frames, and scan for reading data.
#Using r to write res2dinv files windows#
Merging the Files into a Single Dataframe When you type a command in the Windows console (command prompt), the output from that command goes to two separate streams. For example, if you want the files in the folder C:/foo/, you could use the following code: If you want it to list the files in a different directory, just specify the path to list.files. In the following example, we use the FileWriter class together with its write() method to write some text to the file we created in the example above. As I haven’t specified any target directory to list.files(), it just lists the files in the current working directory.
![using r to write res2dinv files using r to write res2dinv files](https://www.mdpi.com/water/water-10-01498/article_deploy/html/images/water-10-01498-g007.png)
For this, the list.files() function can be used. These formats are used when R objects are saved for later use. R also has two native data formatsRdata (sometimes shortened to Rda) and Rds. Whether the data was prepared using Excel (in CSV, XLSX, or TXT format), SAS, Stata, SPSS, or others, R can read and load the data into memory. Next, it’s just a case of getting a list of the files in the directory. R is capable of reading data from most formats, including files created in other statistical packages.
![using r to write res2dinv files using r to write res2dinv files](https://ars.els-cdn.com/content/image/1-s2.0-S0098300419308192-gr11.jpg)
Set the Directoryīegin by setting the current working directory to the one containing all the files that need to be merged: I recently needed to do this, and it’s very straightforward. In this post, I provide a simple script for merging a set of files in a directory into a single, large dataset.