From 66d21fee87ae014ee4bd76556dfa59151e18b3fa Mon Sep 17 00:00:00 2001 From: aakbarie Date: Wed, 13 May 2015 21:37:44 -0700 Subject: [PATCH] final files --- .gitignore | 3 +++ Code-for-NZ.Rproj | 13 +++++++++++++ from wide to long in R.R | 41 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+) create mode 100644 .gitignore create mode 100644 Code-for-NZ.Rproj create mode 100644 from wide to long in R.R diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..807ea25 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.Rproj.user +.Rhistory +.RData diff --git a/Code-for-NZ.Rproj b/Code-for-NZ.Rproj new file mode 100644 index 0000000..734b20d --- /dev/null +++ b/Code-for-NZ.Rproj @@ -0,0 +1,13 @@ +Version: 1.0 + +RestoreWorkspace: Default +SaveWorkspace: Default +AlwaysSaveHistory: Default + +EnableCodeIndexing: Yes +UseSpacesForTab: Yes +NumSpacesForTab: 8 +Encoding: UTF-8 + +RnwWeave: Sweave +LaTeX: pdfLaTeX diff --git a/from wide to long in R.R b/from wide to long in R.R new file mode 100644 index 0000000..d6f1fcd --- /dev/null +++ b/from wide to long in R.R @@ -0,0 +1,41 @@ +library(tidyr) + +meta_data = read.csv("C:\\Users\\Akbar Akbari Esfahan\\Google Drive\\Mikes\\Code-for-NZ\\layer_depth.csv",header=T) +setwd("C:\\Users\\Akbar Akbari Esfahan\\Google Drive\\Mikes\\Code-for-NZ") +files <- list.files(pattern=".csv") +files + +create_f = function(file) +{ + data = as.data.frame(lapply(file, read.csv,header=T)) + dim(data) + temp1 = data[,1:24] + data_long <- gather(temp1, depth, resistivity, res1:res21) + data_long$depth = as.character(data_long$depth) + + for(i in 1:length(meta_data[,1])) + { + data_long$Layer[data_long$depth == meta_data[i,3]] = meta_data[i,1] + data_long$depth[data_long$depth == meta_data[i,3]] = meta_data[i,2] + } + + write.csv(data_long,paste(file,"_short.csv"),row.names=F) + #For all res values + data_long <- gather(data, depth, resistivity, res1:res24) + data_long$depth = as.character(data_long$depth) + + for(i in 1:length(meta_data[,1])) + { + data_long$Layer[data_long$depth == meta_data[i,3]] = meta_data[i,1] + data_long$depth[data_long$depth == meta_data[i,3]] = meta_data[i,2] + } + + + write.csv(data_long,paste(file,"_long.csv"),row.names=F) + +} + +create_f("Morrill_block_test_75%(2)_voxler.csv") +create_f("Morrill_block_test_75%(1)_voxler.csv") +create_f("Morrill_block_test_known_75%(2)_voxler.csv") +create_f("Morrill_block_test_known_75%(1)_voxler.csv") \ No newline at end of file