Skip to content

Instantly share code, notes, and snippets.

@janeshdev
Last active August 29, 2015 13:56
Show Gist options
  • Save janeshdev/9086802 to your computer and use it in GitHub Desktop.
Save janeshdev/9086802 to your computer and use it in GitHub Desktop.
This function was created to convert the velocity with magnitude and direction from EFDC similar to x and y velocity components. #velocityxy #velocity
# A function to convert velocity xy EFDC file to velocity component file
velxy_convert <- function(file){
process_pp_template <- function(path) {
# Read data using quicktoolsr function
dat <- readts_EE(path)
# Reshape the data from long format to wide format
dat_mod <- dcast(dat, time ~ id)
return(dat_mod)
}
# Read the file
dat <- data.frame(process_pp_template(file))
nn <- ncol(dat)
new_nn <- (nn-1)/2
tempvel <- sapply(1:new_nn,function(x)ifelse(dat[,(2*x)]<0, -1 * dat[,((2*x)+1)], dat[,((2*x)+1)]))
# vel <- data.frame(dat$time,tempvel)
# names(vel) <- c("time", rep("temp",ncol(tempvel)))
# vel_final <- sapply(1:(ncol(vel)), function(x) data.frame(vel$time, vel[,x]))
# return(vel_final)
return(tempvel)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment