[R] Trouble with arguments to 'order'

Patrick Burns pburns at pburns.seanet.com
Tue May 28 10:12:45 CEST 2013


If I understand your problem correctly,
you want to use '[[' instead of '$':

order(parameters[["ItemColumn"]], parameters[["PriceColumn"]])



On 28/05/2013 07:06, Barry King wrote:
> I have an Excel worksheet with 20 rows.  Using XLConnect I successfully
> read the data into 'indata'.  In order to sort it on the 'Item' column
> and the 'Price_Per_Item' column I submit:
>
> index <- with(indata, order(Item, Price_Per_Item))
> sortedData <- indata[index, ]
>
> The above works fine but now I do not want to name the columns in the
> R program directly but pass the names of the columns from a parameter file:
>
> index <- with(indata, order(parameters$ItemColumn,
>                              parameters$PriceColumn))
> sortedData <- indata[index, ]
>
> This does not work. Only one row appears in 'sortedData'.  I've tried
> unlisting the two arguments to 'order' but this does not correct the
> problem.
>
> Can anyone suggest a solution to my problem?  Your assistance is
> appreciated.
>
> - Barry King
>

-- 
Patrick Burns
pburns at pburns.seanet.com
twitter: @burnsstat @portfolioprobe
http://www.portfolioprobe.com/blog
http://www.burns-stat.com
(home of:
  'Impatient R'
  'The R Inferno'
  'Tao Te Programming')



More information about the R-help mailing list