Q:

R - function return only first set of passed parameter

I am running into a strange problem in R. 
In the attached script, I have 2  dataframe containing same data just in reversed order (data_asc, data_desc). Then I apply a same function (fnDoIt) with same parameters to both dataframes to create new column in each (cost). 
The function split the strings by "|" then create a dataframe and return the "cost" element of the dataframe. The parameter_desc contain the parameter names separated by "|" while the parameter_value contain parameter values separated by "|" in same order.
However, when I run the script, it returns different values depend on what order my dataframe is. It seems to return the result of the first set of parameter. 
What I expect to see is:

A-----price|cost--------------10|7----------7 
B-----price|cost|tax_rate-----12|6|0.10-----6

But what i get (depend on the order of data frame) are either:

A-----price|cost--------------10|7----------7 
B-----price|cost|tax_rate-----12|6|0.10-----7

or

B-----price|cost|tax_rate-----12|6|0.10-----6
A-----price|cost--------------10|7----------6

I am not sure how to get around this … really appreciate any help or insight from you guys
Thanks
stringsAsFactors=FALSE

fnDoIt = function(model
              , parameter_desc
              , parameter_value) {
  #process parameters
  #split string, then unlist
  parameter_desc = unlist(strsplit(parameter_desc
                                   , split = '|'
                                   , fixed = TRUE))

  #split string, then unlist, then convert to number
  parameter_value = as.numeric(unlist(strsplit(parameter_value
                                               , split = '|'
                                               , fixed = TRUE)))

  #build dataframe for parameters
  parameter = as.data.frame(t(parameter_value)) #transpose vector to horizontal
  names(parameter) = parameter_desc #rename columns

  fnDoIt = parameter$cost 
}

data = data.frame(model = c('A','B')
                  , parameter_desc = c('price|cost','price|cost|tax_rate')
                  , parameter_value = c('10|7','12|6|0.10'))

data_asc = data
data_desc = data[order(data$model, decreasing = TRUE),]

data_asc$cost = fnDoIt(data_asc$model
                       , data_asc$parameter_desc
                       , data_asc$parameter_value)

data_desc$cost = fnDoIt(data_desc$model
                        , data_desc$parameter_desc
                        , data_desc$parameter_value)

UPDATED:
options(stringsAsFactors = FALSE)
fnDoIt = function(model
                  , production
                  , parameter_desc
                  , parameter_value) {

  #process parameters
  #split string, then unlist
  parameter_desc = unlist(strsplit(parameter_desc
                                   , split = '|'
                                   , fixed = TRUE))

  #split string, then unlist, then convert to number
  parameter_value = as.numeric(unlist(strsplit(parameter_value
                                               , split = '|'
                                               , fixed = TRUE)))

  if (model == 'A') {
    temp = parameter_value[parameter_desc == 'cost']
  } else if (model == 'B') {
    temp = parameter_value[parameter_desc == 'tax_rate']
  }

  fnDoIt = temp * production
}

data = data.frame(model = c('A','B','B')
                  , production = c(100,185,210)
                  , parameter_desc = c('price|cost','price|cost|tax_rate','price|cost|tax_rate')
                  , parameter_value = c('10|7','14|9|0.20','12|6|0.10'))

data$cost = ifelse(data$model == 'A'
                       , fnDoIt('A'
                                , data$production
                                , data$parameter_desc
                                , data$parameter_value)
                       , fnDoIt('B'
                                , data$production
                                , data$parameter_desc
                                , data$parameter_value))

I received the error: 

In temp * production: longer object length is not a multiple of
  shorter object length

A:

I think this is what you are looking for,
fnGetCost <- function(df){
  apply(df, 1, 
    function(r){
      parms <- unlist(strsplit(r[2], split="\\|")) 
      costIX <- which(parms == "cost")
      as.numeric(unlist(strsplit(r[3], split="\\|"))[costIX])
    })
}

data_asc$cost = fnGetCost(data_asc)

data_desc$cost = fnGetCost(data_desc)

Your original solution is considering all the rows at once. Check the output of 
unlist(strsplit(as.character(data_asc$parameter_desc)
            , split = '|'
            , fixed = TRUE))

So finally you have multiple columns with column names cost while you are returning only one of them. If you really want to use your function replace the last three line with 
parameter_value[parameter_desc == "cost"]

Additionally note that the original function throws an error as the columns of data are coerced to factor

