Shivi Bhatia
2018-Mar-17 15:08 UTC
[R] length of 'dimnames' [2] not equal to array extent- For Correlation Plot
Created a new data set with 3 numeric variable to find correlation CR1<- mar%>% as_data_frame%>% select(AGE, OLD_CAR_PURCHASE_YRS, Total.Spend.With.AA) had to convert it to a data frame, code: as.matrix(as.data.frame(CR1)) Now i need to run a correlation plot for these 3 variables: corrplot(CR1, method = "circle") But i am getting this error: Error in matrix(unlist(value, recursive = FALSE, use.names = FALSE), nrow nr, : length of 'dimnames' [2] not equal to array extent Researched and found Correlation <https://stackoverflow.com/questions/43362420/length-of-dimnames-2-not-equal-to-array-extent-when-using-corrplot-function>that corrplot requires a matrix however the error is still the same. Regards, Shivi [[alternative HTML version deleted]]
Sarah Goslee
2018-Mar-17 15:15 UTC
[R] length of 'dimnames' [2] not equal to array extent- For Correlation Plot
I'm assuming you are using the corrplot package. If so, your data object does need to be a matrix, not a data frame. Since it's already a data frame, your line of code: as.matrix(as.data.frame(CR1)) doesn't need the as.data.frame function, but more importantly, you didn't assign the result to anything: as.matrix() does not work in place. CR1 <- as.matrix(CR1) Now try. If that doesn't work, then provide a reproducible example so we can offer further advice. Sarah On Sat, Mar 17, 2018 at 11:08 AM, Shivi Bhatia <shivipmp82 at gmail.com> wrote:> Created a new data set with 3 numeric variable to find correlation > > CR1<- mar%>% as_data_frame%>% select(AGE, OLD_CAR_PURCHASE_YRS, > Total.Spend.With.AA) > > had to convert it to a data frame, code: > > as.matrix(as.data.frame(CR1)) > > Now i need to run a correlation plot for these 3 variables: > > corrplot(CR1, method = "circle") > > But i am getting this error: > Error in matrix(unlist(value, recursive = FALSE, use.names = FALSE), nrow > nr, : length of 'dimnames' [2] not equal to array extent > Researched and found Correlation > <https://stackoverflow.com/questions/43362420/length-of-dimnames-2-not-equal-to-array-extent-when-using-corrplot-function>that > corrplot requires a matrix however the error is still the same. > Regards, Shivi > > [[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.-- Sarah Goslee http://www.functionaldiversity.org
Shivi Bhatia
2018-Mar-17 16:00 UTC
[R] length of 'dimnames' [2] not equal to array extent- For Correlation Plot
Hi Sarah, Thank you for your help. I tried using CR1<-as.matrix(CR1) but gives error Error in corrplot(CR1, method = "circle") : The matrix is not in [-1, 1]!. I am using a corrplot library. Please find the reproducible example: dput(head(CR1,10)) structure(c(26L, 46L, 39L, 38L, 47L, 59L, 56L, 61L, 43L, 60L, 78L, 63L, 2L, 58L, 8L, 1L, 1L, 9L, 11L, 2L, 1037500L, 46747L, 346300L, 672000L, 729000L, 470800L, 423000L, 72184L, 368022L, 1037500L), .Dim = c(10L, 3L), .Dimnames = list(NULL, c("AGE", "OLD_CAR_PURCHASE_YRS", "Total.Spend.With.Maruti"))) Please advice if this would help. Thank you. Shivi On Sat, Mar 17, 2018 at 8:45 PM, Sarah Goslee <sarah.goslee at gmail.com> wrote:> I'm assuming you are using the corrplot package. > > If so, your data object does need to be a matrix, not a data frame. > Since it's already a data frame, your line of code: > > as.matrix(as.data.frame(CR1)) > > doesn't need the as.data.frame function, but more importantly, you > didn't assign the result to anything: as.matrix() does not work in > place. > > CR1 <- as.matrix(CR1) > > Now try. > > If that doesn't work, then provide a reproducible example so we can > offer further advice. > > Sarah > > On Sat, Mar 17, 2018 at 11:08 AM, Shivi Bhatia <shivipmp82 at gmail.com> > wrote: > > Created a new data set with 3 numeric variable to find correlation > > > > CR1<- mar%>% as_data_frame%>% select(AGE, OLD_CAR_PURCHASE_YRS, > > Total.Spend.With.AA) > > > > had to convert it to a data frame, code: > > > > as.matrix(as.data.frame(CR1)) > > > > Now i need to run a correlation plot for these 3 variables: > > > > corrplot(CR1, method = "circle") > > > > But i am getting this error: > > Error in matrix(unlist(value, recursive = FALSE, use.names = FALSE), > nrow > > nr, : length of 'dimnames' [2] not equal to array extent > > Researched and found Correlation > > <https://stackoverflow.com/questions/43362420/length-of- > dimnames-2-not-equal-to-array-extent-when-using-corrplot-function>that > > corrplot requires a matrix however the error is still the same. > > Regards, Shivi > > > > [[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. > > > > -- > Sarah Goslee > http://www.functionaldiversity.org >[[alternative HTML version deleted]]
Maybe Matching Threads
- length of 'dimnames' [2] not equal to array extent- For Correlation Plot
- length of 'dimnames' [2] not equal to array extent- For Correlation Plot
- length of 'dimnames' [2] not equal to array extent- For Correlation Plot
- arguments imply differing number of rows
- arguments imply differing number of rows