matrix
trwa data
i kolejne argumenty nrow
i ncol
.
?matrix
If one of ‘nrow’ or ‘ncol’ is not given, an attempt is made to
infer it from the length of ‘data’ and the other parameter. If
neither is given, a one-column matrix is returned.
as.matrix
jest metodą z różnych zachowań dla różnych rodzajów, lecz przede wszystkim oddać n * m z m macierzy wejścia n *.
?as.matrix
‘as.matrix’ is a generic function. The method for data frames
will return a character matrix if there is only atomic columns and
any non-(numeric/logical/complex) column, applying ‘as.vector’ to
factors and ‘format’ to other non-character columns. Otherwise,
the usual coercion hierarchy (logical < integer < double <
complex) will be used, e.g., all-logical data frames will be
coerced to a logical matrix, mixed logical-integer will give a
integer matrix, etc.
Różnica między nimi pochodzi przede wszystkim od kształtu wejściu, matrix
nie dba o kształcie, as.matrix
robi i będzie ją utrzymywać (choć szczegóły zależą od aktualnych metod wejścia, aw sprawa bezwymiarową wektor odpowiada jednej matrycy kolumnowej). nie ma znaczenia, czy sygnał wejściowy jest surowy, logiczne całkowitą numeryczna, postać lub kompleks itp
Przeczytaj dokumentację. Np. Porównaj dane wyjściowe z 'DF <- data.frame (a = 1: 5, b = 6: 10); as.matrix (DF); matrix (DF) '. – Roland
tak, ale nie mam do czynienia z data.frame, tj. Moja macierz jest tylko danymi liczbowymi. –
Pytasz o różnicę między tymi funkcjami. Różnica jest udokumentowana i pokazałem ci przykład. To, że funkcje mogą (w określonych okolicznościach) dawać taki sam wynik, nie ma wpływu na odpowiedź na twoje pytanie. – Roland