# "Error in make.unique(bi, sep = sep): 'names' must be a character vector"? Any suggestions to solve it?

I need your help in solving an error related to vector name

I'm trying to define the function- ginv2 in r to convert a matrix output into fraction format but, I got an error related to 'names'.

```````Error in make.unique(bi, sep = sep) : 'names' must be a character vector`
``````

Here are the details of my goals and codes that I tried: I'm trying to achieve contrast coding for one of the predictor variables in the linear mixed effect model. I want to use the repeated contrast coding for a variable(AgeRange) with four levels.

To code the repeated contrast in r, I followed 4 steps prescribed in D.J. Schad, et, al.(2020)

##Step1~ specify hypothesis:

``````# HoII-I:  -1.I + 1.II + 0.III + 0.IV = 0
# HoIII-II: 0.I - 1.II + 1.III + 0.IV = 0
# HoIV-III: 0.I + 0.II - 1.III + 1.IV = 0
``````

##Step2~ create vector weights for all the hypotheses for this data

`````` cIIvsI <- c(AgeRangeI=-1, AgeRangeII= +1, AgeRangeIII= 0, AgeRangeIV= 0)
cIIIvsII <- c(AgeRangeI= 0, AgeRangeII= -1, AgeRangeIII= +1, AgeRangeIV= 0)
cIVvsIII <- c(AgeRangeI= 0, AgeRangeII= 0, AgeRangeIII= -1, AgeRangeIV= +1)
``````

##Step3~ extract and code the weights from all the hypotheses and convert them into hypothesis matrix in R

``````RTacc.df2424\$AgeRange <- factor(RTacc.df2424\$AgeRange)
AgeRange.contrast <- rbind (
cIIvsI <- c(AgeRangeI=-1, AgeRangeII= +1, AgeRangeIII= 0, AgeRangeIV= 0),
cIIIvsII <- c(AgeRangeI= 0, AgeRangeII= -1, AgeRangeIII= +1, AgeRangeIV= 0),
cIVvsIII <- c(AgeRangeI= 0, AgeRangeII= 0, AgeRangeIII= -1, AgeRangeIV= +1))

fractions(t(AgeRange.contrast))
[,1] [,2] [,3]
AgeRangeI   -1    0    0
AgeRangeII   1   -1    0
AgeRangeIII  0    1   -1
AgeRangeIV   0    0    1
``````

##Step4 ~ define the generalize inverse to obtain a new contrast matrix XcRE.

##This is to achieve the generalised invers matrix that exactly tests the hypotheses coded which provides the code in fractions format

Before applying generalise inverse to the hypothesis matrix, we need to define the ginv2 function.

``````ginv2 <- function(x)
fractions(provideDimnames(ginv(x),
base = dimnames(x)[2:1]))
``````

After defining ginv2, I passed the AgeRange contrast matrix to the ginv2 function

``````ginv2(AgeRange.contrast)
``````

This gives an error~~

``````Error in make.unique(bi, sep = sep) : 'names' must be a character vector

5.make.unique(bi, sep = sep)
4.provideDimnames(ginv(x), sep = "", base = dimnames(x)[2:1])
3..rat(x, cycles, max.denominator)
2.fractions(provideDimnames(ginv(x), sep = "", base = dimnames(x)[2:1]))
1.ginv2(AgeRange.contrast)
``````

How to resolve this error issue? Any feedback and suggestions on defining the function correctly will be helpful.