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).