0

I am attempting to perform an additive log ratio transformation on a dataset. When I run the addLR() function, I receive the error code:

Error in if (dim(x)[2] < 2) stop("data must be of dimension greater equal 2") : argument is of length zero

When I run str(df) the structure of my data frame returns as:

'data.frame':   1020 obs. of  2 variables:
 $ SUB: int  1 1 1 1 1 1 1 1 1 1 ...
 $ NEW  : num  2.5 351.4 0.9 49.8 80 ...

Here's my code:

df <- read.csv("data.csv",head=TRUE,sep=",")
df$newVar <- addLR(df$NEW, ivar=ncol(df$SUB))

I've also used the function

df$newVar <- alr(df$NEW, ivar=ncol(df$SUB))

but only receive the error message

Error in -ivar : invalid argument to unary operator

I've tried altering the class of both variables (i.e.df$SUB <- as.character(df$SUB)), as well as ensuring the length of both columns are equal (they are).

MrFlick
  • 195,160
  • 17
  • 277
  • 295
A. Baker
  • 9
  • 2
  • See [how to create a reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) (it's better to post a `dput()` rather than an `str()`). Also explicitly mention any packages you are using, `addLR` is not a base function. – MrFlick Sep 06 '16 at 03:06
  • Is `addLR` from `robCompositions` ? – steveb Sep 06 '16 at 03:59
  • This may be what you need for `addLR`: `addLR(df, ivar=ncol(df))`. – steveb Sep 06 '16 at 04:12

0 Answers0