Error in dimnames x dn length of dimnames 2 not equal to array extent

I have changed a little bit my R code that worked perfectly,but instead 3 now I have 7 clusters. layout(matrix(c(1, 1, 2, 2, 3, 3, 4, 4, 5), ncol=1)) # main plots par(mai=rep(0.5, 4)) fcm <-c...

I have changed a little bit my R code that worked perfectly,but instead 3 now I have 7 clusters.

layout(matrix(c(1, 1, 2, 2, 3, 3, 4, 4, 5), ncol=1))

# main plots
par(mai=rep(0.5, 4))

fcm <-c(14.0,14.1,13.0,14.2,14.7,13.8,14.0)
gk  <-c(12.1,12.5,12.2,12.0,11.5,12.0,11.4)
gg  <-c(14.0,14.1,13.3,12.8,12.0,12.2,12.0)
data1 <- rbind(fcm,gk,gg)
colnames(data1) <- c(6,7,8,9,10,11,12)

fcm <-c(2.65,2.55,2.4,2.45,2.45,2.5,2.45)
gk  <-c(2.45,2.55,2.4,2.3,2.2,2.35,2.1)
gg  <-c(2.6,2.65,2.5,2.35,2.4,2.4,2.2)
data2 <- rbind(fcm,gk,gg)
colnames(data2) <- c(6,7,8,9,10,11,12)

fcm <-c(8.8,6.5,6.6,8.2,8.0,8.4,9.0)
gk  <-c(12.7,11.0,11.1,10.5,10.7,10.0,9.5)
gg  <-c(2.1,2.1,1.8,2.0,2.0,1.9,1.8)
data3 <- rbind(fcm,gk,gg)
colnames(data3) <- c(6,7,8,9,10,11,12)

fcm <-c(0.47,0.53,0.45,0.39,0.40,0.47,0.48)
gk  <-c(0.45,0.51,0.34,0.40,0.42,0.42,0.44)
data4 <- rbind(fcm,gk)
colnames(data4) <- c(6,7,8,9,10,11,12)

barplot(as.matrix(data1),ylim=c(0,20),main="P wave",
        xlab="number of clusters", ylab="traveltime rms(ms)",
        col=c("red", "black", "green"), beside=TRUE)
barplot(as.matrix(data2),ylim=c(0,2),main="MT",
        xlab="number of clusters", ylab="MT functions",
        col=c("red", "black", "green"), beside=TRUE)
barplot(as.matrix(data3),ylim=c(0,20),main="XBI",
        xlab="number of clusters", ylab="index value",
        col=c("red", "black", "green"), beside=TRUE)
barplot(as.matrix(data4),ylim=c(0,0.6),main="NCE",
        xlab="number of clusters", ylab="index value",
        col=c("red", "black"), beside=TRUE)

par(mai=c(0,0,0,0))
plot.new()
legend(legend = c("fcm","gk","gg"), fill = c( "red", "black", "green"), 
    "center", horiz=TRUE)

But then I got

Error in `colnames<-`(`*tmp*`, value = c(6, 7, 8, 9, 10, 11, 12)) : 
  length of 'dimnames' [2] not equal to array extent

The problem is with the rbind.I am combining 3 vectors,each of them has 7 elements.What should I change?I want that each element has the proper number of clusters labeled behind.

Sometimes in R programming, You need to create blank datasets to add data to later on. when dealing with data frames it is necessary to make sure that you set up the right number of column names otherwise you will get the “error in dimnames(x) = dn : length of ‘dimnames’ [2] not equal to array extent” error message. Fortunately, it is an easy problem to fix.

Description of the error

This error message occurs when you are setting up a blank matrix or a data frame using a blank matrix and the number of column names you supply is fewer than the number of columns that you defined. It is easy to get this error message because this is an unusual way of setting up a data frame, as a result in the process you may leave out one or more column names from the vector defining them. In such cases correcting the problem is simple because all you need to do, if everything else is right, is add the needed column names.

Explanation of the error

Here are two code examples that produce our error message. They each show it being caused under slightly different circumstances.

> df = data.frame(matrix(vector(),10,5, dimnames=list(c(), c(“A”, “B”, “C”, “D”))))
Error in matrix(vector(), 10, 5, dimnames = list(c(), c(“A”, “B”, “C”, :
length of ‘dimnames’ [2] not equal to array extent

This example is a basic data frame that produces our error message. Note that we have set the number of columns as five, but we only provide four column names.

> work = data.frame(matrix(vector(),14,7, dimnames=list(c(), c(“Bob”, “Sue”, “Tom”, “Becky”, “Ann”, “Jim”))))
Error in matrix(vector(), 14, 7, dimnames = list(c(), c(“Bob”, “Sue”, :
length of ‘dimnames’ [2] not equal to array extent

In this example, we use more meaningful column names. We defined the number of columns as seven, but we only supply six column names.

How to fix the error

Here we have two examples where we fixed the problem. In both cases, it is a simple matter of adding another column name.

> df = data.frame(matrix(vector(),10, 5, dimnames=list(c(), c(“A”, “B”, “C”, “D”, “E”))))
> df
A B C D E
1 NA NA NA NA NA
2 NA NA NA NA NA
3 NA NA NA NA NA
4 NA NA NA NA NA
5 NA NA NA NA NA
6 NA NA NA NA NA
7 NA NA NA NA NA
8 NA NA NA NA NA
9 NA NA NA NA NA
10 NA NA NA NA NA

In this example, we simply added a call named “E” to fix the problem. The result is a perfectly good data frame of missing values.

> work = data.frame(matrix(vector(),14,7, dimnames=list(c(), c(“Bob”, “Sue”, “Tom”, “Sindy”, “Ann”, “Jim”, “Al”))))
> work
Bob Sue Tom Sindy Ann Jim Al
1 NA NA NA NA NA NA NA
2 NA NA NA NA NA NA NA
3 NA NA NA NA NA NA NA
4 NA NA NA NA NA NA NA
5 NA NA NA NA NA NA NA
6 NA NA NA NA NA NA NA
7 NA NA NA NA NA NA NA
8 NA NA NA NA NA NA NA
9 NA NA NA NA NA NA NA
10 NA NA NA NA NA NA NA
11 NA NA NA NA NA NA NA
12 NA NA NA NA NA NA NA
13 NA NA NA NA NA NA NA
14 NA NA NA NA NA NA NA

In this example, we added the column name “Al” to bring the number of column names up to seven. This fixes the problem by producing a perfect data frame of missing values.

This is a pretty interesting error message to encounter. While it is easy to stumble into, it is also easy to fix. Fixing this problem simply requires adding the number of column names that you need. So if you encounter this error message do not feel bad, all you need to do is add one or more column names.

@prxrsp

Hello,

I am trying to run my own data and I bump into this error message when I prepare_ceres_inputs

_getting copy number data per locus…

Error in dimnames(x) <- dn :
length of ‘dimnames’ [2] not equal to array extent_

Any suggestions?

@prxrsp

Hi again,

It seems that the code breaks at intersect_guide_with_copy_number. The issue I think only appears if I run a single cell line and it has to do with selecting column CN from cn_seg_gr. I will redo with two cell lines and see if it runs smoothly.

UPDATE: It runs smoothly with at least two cell lines.

Thanks!

@funpys

Hi,
I’ve got same problem, and solved in same way, using additional dummy cell line.
However, it seems that the output is changing with same input data according to data of dummy cell line.
Didn’t you face this problem?

@prxrsp

Hello,

I understand that CERES shares information across cell lines, although I have yet to look through the code and find what kind of information is shared. But that pretty much explains your problem.

I would not use a dummy column. If you only have the single cell line, perhaps you can add a cell line from CERES example data, as they are ready to run. That being said, until we figure out what part of the code shares information across cell lines, you cannot be confident that your results are reliable.

I hope this helps.

@j-g-b

Thanks for your patience, guys. I’m working on pushing a patch that will take care of the single cell line case.

@prxrsp is right to say that the output will change because CERES tries use the dummy cell line as an informative partner. The sharing is done through an additive fixed effects term in the mixed effects model representing something like the «average gene effect across all cell lines», from which each individual cell line may differ. The model regularizes the cell-line-specific effects towards this mean effect, though, so if the values of your dummy cell line change, then so will those in your cell line of interest. I would not recommend adding fake cell line data for this reason.

The problem is definitely in prepare_inputs and probably has to do with a dimensionless array getting generated when a matrix is expected somewhere. I’ll comment back when I’ve confirmed that a fix is ready.

@j-g-b

The latest commit seems to work with one cell line; let me know how it goes.

FYI we noticed that if you try to run prepare_inputs with a cell line that is not present in the dependency data .gct, one of these dimnames errors pops up, so double-check that all of the names match.

@funpys

Thanks for nice comments, I will let you know when I get the result.
I have one more question.
When I run wrap_ceres, I used several replicates for each cell line as a input, then final output is only 1 column for 1 cell line. I searched codes in wrap_ceres, but final step (fit_ceres) seems quite complicated. Could you tell me how replicates are merged to one column?

@funpys

Bellow is the error message from prepare_ceres_input with single cell line data.

getting copy number data per locus…

Error in set_rownames(., rownames(.) %>% str_extract(«chr.+$»)) :
attempt to set ‘rownames’ on an object with no dimensions

I think intersect_locus_with_cn_seg need to be revised for single cell line data.

@j-g-b

I think I fixed the problem, which was occurring because a 1-d matrix was being indexed at its rows, and R returns dimensionless vectors unless one specifies one_d_mat[1:10, , drop=F]

Hopefully that takes care of everything. Again, let us know if that doesn’t solve the problem or creates further issues.

As for your previous comment, CERES is finding parameters to best fit the data for each guide i and cell line j. If there’s only one replicate of that guide / cell line pair, then CERES will output one value for that one data point and evaluate the squared error. When multiple replicates are present, CERES still only outputs one value for guide i and cell line j, but now the mean squared error across the replicate data points is calculated.

@funpys

Thanks a lot!
Actually, I’ve got another error in same step.

getting copy number data per locus…

Error in x[!i, ] : incorrect number of dimensions

@j-g-b

Terribly sorry for taking so long to get around to this. I think I resolved the issue which had to do with matrix dimensions getting dropped in the case of a single cell line.

MultiAssayExperiment: Error in dimnames(x) <- dn : length of ‘dimnames’ [2] not equal to array extent

@mariozanfardino-15232

Last seen 2.5 years ago

Naples (Italy)

I have the following MAE:​

> data
A MultiAssayExperiment object of 4 listed
experiments with user-defined names and respective classes.
Containing an ExperimentList class object of length 4:
[1] BRCA_miRNASeqGene-20160128: SummarizedExperiment with 500 rows and 65 columns
[2] BRCA_RNASeqGene-20160128: SummarizedExperiment with 500 rows and 187 columns
[3] exp_1: SummarizedExperiment with 500 rows and 65 columns
[4] exp_2: SummarizedExperiment with 500 rows and 65 columns 

When i run wideformat function on data i have the following error (but only when patients are > 107):

 > wideFormat(data[1:20, 1:108, ])
 Error in dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent

Any suggestions?

multiassayexperiment

wide format

TCGA

• 3.8k views

@marcel-ramos-7325

Last seen 7 days ago

United States

Ciao Mario,
Thanks for reporting this.

This should be fixed in MultiAssayExperiment version 1.7.21.

Best regards,
Marcel

Login before adding your answer.

Traffic: 523 users visited in the last hour

Error in dimnames(x) <- dn : length of ‘dimnames’ [1] not equal to array extent

Hi,

I am trying to create a heatmap.

Before I need to transform my dataset:

data <- heatmap_data
rnames <- data[,1]                            # assign labels in column 1 to "rnames"
mat_data <- data.matrix(data[,2:ncol(data)])  # transform columns (I have) into a matrix
rownames(mat_data) <- rnames                  # assign row names

But when I run the last one I get this error message:

   Error in dimnames(x) <- dn : 
  length of 'dimnames' [1] not equal to array extent

If I do:

head(data)
ID                          s21   s22   s23   s24   s25   s31   s32   s33   s34   s35
  <chr>                     <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 TRINITY_DN34816_c1_g1_i2  0.233 0     1.31  0.127 0.822 2.06  1.44  0.749 1.79  2.61 
2 TRINITY_DN10000_c0_g1_i1  3.01  1.78  1.38  0.798 0.855 3.18  2.99  3.54  3.05  1.20
3 TRINITY_DN100041_c0_g1_i1 3.66  2.80  2.14  1.21  1.26  3.83  3.85  4.27  3.76  1.98 
4 TRINITY_DN100086_c0_g1_i1 0.556 0.438 0.176 0.145 0.03  0.533 0.511 0.524 0.344 0.134
5 TRINITY_DN19297_c0_g1_i1  0.559 0.23  0.224 0.11  0.024 1.12  1.08  2.08  2.05  0.56 
6 TRINITY_DN133973_c0_g1    0     0.275 0     0     0     2.48  0.964 2.18  0.8   1.34

and

head(mat_data)
   s21   s22   s23   s24   s25   s31   s32   s33   s34   s35
[1,] 0.233 0.000 1.309 0.127 0.822 2.062 1.435 0.749 1.788 2.610
[3,] 3.664 2.799 2.137 1.207 1.258 3.828 3.849 4.269 3.760 1.984
[4,] 0.556 0.438 0.176 0.145 0.030 0.533 0.511 0.524 0.344 0.134
[5,] 0.559 0.230 0.224 0.110 0.024 1.118 1.085 2.084 2.046 0.560
[6,] 0.000 0.275 0.000 0.000 0.000 2.477 0.964 2.176 0.800 1.340

How can I solve this problem?

R

heatmap

error

• 45k views

Solved!

It was a problem with the title of the first column :)

The reason for the error is because the data was not classified as data.frame
I solved this by adding a new line in the syntax.

    data <- heatmap_data
    data<-as.data.frame(data) # New line added
    rnames <- data[,1]                            # assign labels in column 1 to "rnames"
    mat_data <- data.matrix(data[,2:ncol(data)])  # transform columns (I have) into a matrix
    rownames(mat_data) <- rnames                  # assign row names

Login before adding your answer.

r - Error : length of dimnames [2] not equal to array extent

You need to supply one more column name. Your data has eight columns, as can be seen, e.g., with

> length(fcm)
[1] 8

or

> ncol(data1)
[1] 8

or by displaying the matrix:

> data1
#    [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
#fcm 14.0 14.1 13.0   14  2.0 14.7 13.8 14.0
#gk  12.1 12.5 12.2   12  0.0 11.5 12.0 11.4
#gg  14.0 14.1 13.0    3 12.8 12.0 12.2 12.0

while

> length( c(6, 7, 8, 9, 10, 11, 12))
[1] 7

You could try with

colnames(data1) <- c(6:13)

With your data, this would be:

fcm <-c(14.0,14.1,13.0,14,2,14.7,13.8,14.0)
gk  <-c(12.1,12.5,12.2,12,0,11.5,12.0,11.4)
gg  <-c(14.0,14.1,13,3,12.8,12.0,12.2,12.0)
data1 <- rbind(fcm,gk,gg)
colnames(data1) <- c(6:13)

which gives:

> data1
       6    7    8  9   10   11   12   13
fcm 14.0 14.1 13.0 14  2.0 14.7 13.8 14.0
gk  12.1 12.5 12.2 12  0.0 11.5 12.0 11.4
gg  14.0 14.1 13.0  3 12.8 12.0 12.2 12.0

without any error message.

r – Error : length of dimnames [2] not equal to array extent

Related posts on array :

  • c++ – Remove duplicates from an unsorted array
  • Declaring an array in pseudocode
  • Difference between ArrayIterator, ArrayObject and Array in PHP
  • php – array_walk_recursive with array?
  • Return Largest Numbers in Arrays in javascript
  • set – No Java implementations for arrayset
  • java – Finding the second smallest integer in array
  • Correct way to synchronize ArrayList in java

Hi!

I have prepared a script to compute a linear growth model to estimate genetic and environmental influences (ACE) in an intake and a slope with ordinal twin data: 4 variables, 3 categories (2 thresholds) in each of them. The sample is is divided in 6 groups (and so is the script), according to zygosity and sex: MZ men, DZ men, MZ women, DZ women, DZ man-woman and DZ woman-man.

I get an error message indicating the following sentence:
> Error: The algebra ‘ACE.expThre’ in model ‘lgcOrdACE’ generated the error message: length of ‘dimnames’ [1] not equal to array extent

The matrix concerning the error message («expThre») is specified in the script as follows:

> mxMatrix( type=»Full», nrow=1, ncol=nv, free=F, labels=»th1″, values=0, name=»t1″ ),
> mxMatrix( type=»Full», nrow=1, ncol=nv, free=T, labels=»th2″, values=.1, name=»t2″ ),
> mxAlgebra( expression=(rbind(t1,t2)), name=»Th» ),
> mxMatrix( type=»Lower», nrow=nth, ncol=nth, free=FALSE, values=1, name=»Inc» ),
> mxMatrix( type=»Full», nrow=nv, ncol=nf, free=F, values=c(1,1,1,1,0,1,2,3), name=»fl» ),

> mxMatrix( type=»Unit», nrow=2, ncol=1, name=»UnitV1″ ),
> mxMatrix( type=»Unit», nrow=1, ncol=nv, name=»UnitV2″ ),
> mxAlgebra( expression= (UnitV1 %x% (Inc %% Th)) — (UnitV2 %x% (fl %% Mean)), name=»ThInc»),
> mxAlgebra( expression= cbind(ThInc,ThInc), dimnames=list(thRows,selVars), name=»expThre» ),

I am not very familiar with scripting in OpenMx for growth models, so I am not able to understand the error and how can I correct it. I would very much appreciate any help to interpret the meaning of this error message. I have attached the full script with the model if anybody wish to have a look.

Thanks a lot in advance!
Regards,
Alfredo

Понравилась статья? Поделить с друзьями:
  • Error in connection establishment net err connection refused
  • Error in conflict multiple assets emit different content to the same filename index html
  • Error in configuration process project files may be invalid cmake opencv
  • Error in communication with engine kerio control
  • Error in command syntax check command help