Hi, Dear Professor, When I run a code in R, I face the following error: Error in dimnames(x) <- dn : length of 'dimnames' [2] not equal to array extent Kindly help how to handle this. Regards Chishti [[alternative HTML version deleted]]
Hi, you should post a reproducible example if you want to have an answer. This error is generated when you try to copy an object in another of the wrong size. > a <- data.frame(A=1:2) > dimnames(a) [[1]] [1] "1" "2" [[2]] [1] "A" > dn <- list(c("3", "4"), c("B", "D")) > dimnames(a) <- dn Erreur dans `dimnames<-.data.frame`(`*tmp*`, value = list(c("3", "4"), c("B",? : ? 'dimnames' incorrect pour ce tableau de donn?es Marc Le 21/06/2022 ? 15:09, Muhammad Zubair Chishti a ?crit?:> Hi, Dear Professor, > When I run a code in R, I face the following error: > Error in dimnames(x) <- dn : > length of 'dimnames' [2] not equal to array extent > > Kindly help how to handle this. > > Regards > Chishti > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.__________________________________________________________ Marc Girondot, Pr Laboratoire Ecologie, Syst?matique et Evolution Equipe de Processus Ecologiques et Pressions Anthropiques CNRS, AgroParisTech et Universit? Paris-Saclay, UMR 8079 B?timent 362 91405 Orsay Cedex, France Tel: +33 (0)1.69.15.72.30 Mobile: +33 (0)6.20.18.22.16 e-mail: marc.girondot at universite-paris-saclay.fr marc.girondot at gmail.com Web: https://www.ese.universite-paris-saclay.fr/epc/conservation/index.html Skype: girondot
The code used is not shown but the error message seems fairly obvious. Something is trying to change the attribute containing names for the object and is not?changing the same number of items as the object contains. What that is might be clear if you showed some code and perhaps printed out info about?your variable before calling what caused the error and showing what you wanted to change it to. And if you did that in advance, you might see what the error is and fix it without asking here. -----Original Message----- From: Muhammad Zubair Chishti <mzchishti at eco.qau.edu.pk> To: r-help at r-project.org Sent: Tue, Jun 21, 2022 9:09 am Subject: [R] A Request Hi, Dear Professor, When I run a code in R, I face the following error: Error in dimnames(x) <- dn : ? length of 'dimnames' [2] not equal to array extent Kindly help how to handle this. Regards Chishti ??? [[alternative HTML version deleted]] ______________________________________________ R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. [[alternative HTML version deleted]]
Hi Chishti, Try this: dim(x)[2] length(dn)>From your error message, the two will be different. They should be thesame. A wild guess is that the offending line of code should be: dimnames[2]<-1:dn Jim On Tue, Jun 21, 2022 at 11:10 PM Muhammad Zubair Chishti <mzchishti at eco.qau.edu.pk> wrote:> > Hi, Dear Professor, > When I run a code in R, I face the following error: > Error in dimnames(x) <- dn : > length of 'dimnames' [2] not equal to array extent > > Kindly help how to handle this. > > Regards > Chishti > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.