matrix
data
और आगे तर्क nrow
और 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
विभिन्न प्रकार के लिए अलग व्यवहार के साथ एक तरीका है, लेकिन मुख्य रूप से वापस एक n * मी इनपुट से एक 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.
उनके बीच के अंतर मुख्य रूप से इनपुट के आकार से आता है, matrix
आकार के बारे में परवाह नहीं है, as.matrix
करता है और इसे बनाए रखने जाएगा (लेकिन जानकारी के इनपुट के लिए वास्तविक तरीकों पर निर्भर है, और में अपने मामले एक आयामरहित वेक्टर एकल स्तंभ मैट्रिक्स से मेल खाती है।) अगर इनपुट कच्चे, तार्किक, पूर्णांक, आंकिक, चरित्र, या जटिल, आदि
दस्तावेज़ीकरण पढ़ें। उदाहरण के लिए, 'डीएफ <- data.frame (ए = 1: 5, बी = 6: 10) के आउटपुट की तुलना करें; as.matrix (DF); मैट्रिक्स (DF) '। – Roland
हाँ, लेकिन मैं data.frame से निपट नहीं रहा हूं यानी मेरा मैट्रिक्स केवल संख्यात्मक डेटा है। –
आपने इन कार्यों के बीच अंतर के लिए कहा। अंतर दस्तावेज है और मैंने आपको एक उदाहरण दिखाया है। यह कार्य (विशिष्ट परिस्थितियों में) एक ही परिणाम को आपके प्रश्न के उत्तर पर कोई प्रभाव नहीं डाल सकता है। – Roland