I have a matrix "Р" with observations (line by line), for each line I consider the distribution through hist()

breaks - set 50

 A <- hist(P[n,],breaks = 50,plot = F) 

but it turned out that on each line of the matrix A$breaks has a different length, in spite of the fact that the length of all the lines in "Р" same, how to make A$breaks always the same size

 > head(P) P1 P2 P3 P4 P5 P6 [9802,] -3.264212 -3.008633 -2.739602 -3.035536 -3.129696 -3.210405 [9803,] -2.922858 -2.660034 -2.949140 -3.041128 -3.119975 -3.014846 [9804,] -2.582244 -2.864561 -2.954390 -3.031385 -2.928724 -3.031385 [9805,] -2.780997 -2.868646 -2.943775 -2.843604 -2.943775 -3.094031 [9806,] -2.794781 -2.868306 -2.770272 -2.868306 -3.015358 -2.917324 [9807,] -2.801911 -2.705737 -2.801911 -2.946172 -2.849998 -2.753824 > summary(P) P1 P2 P3 P4 P5 P6 Min. :-5.10760 Min. :-5.36900 Min. :-5.74779 Min. :-6.29262 Min. :-7.14529 Min. :-8.36945 1st Qu.:-1.16145 1st Qu.:-1.17022 1st Qu.:-1.17861 1st Qu.:-1.18649 1st Qu.:-1.19516 1st Qu.:-1.20249 Median :-0.07062 Median :-0.07064 Median :-0.07154 Median :-0.07098 Median :-0.07052 Median :-0.07054 Mean :-0.03485 Mean :-0.03530 Mean :-0.03575 Mean :-0.03623 Mean :-0.03673 Mean :-0.03727 3rd Qu.: 1.09945 3rd Qu.: 1.10642 3rd Qu.: 1.11345 3rd Qu.: 1.12163 3rd Qu.: 1.12881 3rd Qu.: 1.13619 Max. : 4.72881 Max. : 5.05836 Max. : 5.51505 Max. : 6.10748 Max. : 6.80844 Max. : 7.68919 

the matrix with the data shortened to 6 columns, in fact columns 200, but I don’t know how to make an example with 200 lines

    1 answer 1

     set.seed(1) P <- matrix(rnorm(200 * 200), 200) dim(P) [1] 200 200 A <- hist(P[10, ], breaks = 50, plot = F) length(A$breaks) [1] 68 A <- hist(P[100, ], breaks = 50, plot = F) length(A$breaks) [1] 62 

    Obviously, the option of setting the number of divisions does not work.

    But you can set the vector of divisions:

     breaks <- seq(range(P)[1], range(P)[2], length.out = 50) A <- hist(P[10, ], breaks = breaks, plot = F) length(A$breaks) [1] 50 A <- hist(P[100, ], breaks = breaks, plot = F) length(A$breaks) [1] 50 

    The range of divisions must correspond to the range of values ​​in the rows, so I took the range of values ​​for the entire matrix.

    • Thanks for the quality response! everything is clear, everything works! :) Thanks again - mr.T
    • @ mr.T if the answer was useful to you, you can mark it as true with the help of the checkmark to the left of the answer, under the arrows. ) - Nick Volynkin