Updated It2charge() and fixed the relevant parts of amperometry2df().

It2charge() is now explicitly meant to be used only from within
other functions, such as amperometry2df().
master
Taha Ahmed 14 years ago
parent f8ad854bd7
commit c810ef66ba

@ -298,10 +298,7 @@ amperometry2df <- function(datafilename, wearea = 1) {
ff <- cbind(ff, currentdensity = currentdensity) ff <- cbind(ff, currentdensity = currentdensity)
# Calculate charge densities and differentials # Calculate charge densities and differentials
charge.df <- It2charge(ff$currentdensity, ff$time) charge.df <- It2charge(ff$currentdensity, ff$time)
ff <- cbind(ff, timediff = charge.df$timediff, ff <- cbind(ff, charge.df)
chargedensity = charge$charge,
sumchargedensity = charge$sumcharge,
dQdt = charge$dQdt)
# #
### Collect attributes of this experiment ### Collect attributes of this experiment
# These attributes are specific for each kind of experiment, # These attributes are specific for each kind of experiment,

@ -17,11 +17,22 @@
################################################## ##################################################
################### It2charge #################### ################### It2charge ####################
################################################## ##################################################
It2charge <- function (current, time) { It2charge <- function (time, current) {
## Calculates charge etc. for amperometric data ## Description:
## current may be a current or a current density ## Calculates cumulative charge, differentials, etc. from
## (up to the calling function to keep track of which it is) ## amperometric data (current and time).
# Calculate the difference of the time vector ## __Intended to be used from within other functions (CHI.R)__
## Usage:
## It2charge(time, current)
## Arguments:
## time: a vector with time data.
## current: a vector of the same length as time, with current data.
## May be either currents or current densities, no matter.
## Value:
## Returns a dataframe with columns:
## timediff, dIdt, charge, sumcharge
#
# Calculate the time vector difference
timediff <- c(time[1], diff(time)) timediff <- c(time[1], diff(time))
# timediff times the current gives the charge, # timediff times the current gives the charge,
# since the time vector can be considered as # since the time vector can be considered as
@ -29,11 +40,11 @@ It2charge <- function (current, time) {
# the current with the time elapsed since the last # the current with the time elapsed since the last
# current measurement (the timediff). # current measurement (the timediff).
charge <- current * timediff charge <- current * timediff
differential <- cumsum(charge) / time dIdt <- current / time
# Prepare the return dataframe # Return value
ff <- data.frame(time = time, timediff = timediff, ff <- data.frame(timediff = timediff,
current = current, charge = charge, dIdt = dIdt, charge = charge,
sumcharge = cumsum(charge), dQdt = differential) sumcharge = cumsum(charge))
return(ff) return(ff)
} }

Loading…
Cancel
Save