R - Strings
Strings ये अनेक characters का एक collection होता है | हर Programming Language के लिए Strings काफी महत्वपूर्ण हिस्सा है |
R Programming में Strings को single quotes(' ') में ये double quotes(" ") में close किया जाता है |
Example for Valid Strings in R
Example पर सभी valid strings दिए हुए है |
single quotes के अन्दर double quotes का इस्तेमाल किया जा सकता है |
double quotes के अन्दर single quotes का इस्तेमाल किया जा सकता है |
Source Code :> str1 = 'I am in single quote' > str1 [1] "I am in single quote" > str2 = "I am in double quote" > str2 [1] "I am in double quote" > str3 = "I am 'in double quote with single quote" > str3 [1] "I am 'in double quote with single quote" > str4 = 'I am "in single quote with double quote' > str4 [1] "I am \"in single quote with double quote"
Example for Invalid Strings in R
Example पर सभी invalid strings दिए हुए है |
single quotes के अन्दर single quotes का इस्तेमाल नहीं किया जा सकता |
double quotes के अन्दर double quotes का इस्तेमाल नहीं किया जा सकता |
Source Code :> str1 = 'I am 'in single quote' Error: unexpected 'in' in "str1 = 'I am 'in" > str2 = "I am "in double quote" Error: unexpected 'in' in "str2 = "I am "in"
Some Functions about Strings in R
String Function | Description |
---|---|
"nchar() | इसका इस्तेमाल string/character vector के length को integer में return करने के लिए किया जाता है | |
paste() | इसका इस्तेमाल character vector को concatenate करके character data type में return करने के लिए इस्तेमाल किया जाता है | |
strsplit() | इसका इस्तेमाल character vector के elements से substring(s) को return करने के लिए किया जाता है | |
sub() | इसका इस्तेमाल string को match करके replace करने के लिए किया जाता है | |
substr()/substring() | इसका इस्तेमाल character vector या string से substring को replace या extract करने के लिए किया जाता है | |
tolower() | इसका इस्तेमाल character vector या string को lowercase में convert करने के लिए किया जाता है | |
toupper() | इसका इस्तेमाल character vector या string को uppercase में convert करने के लिए किया जाता है | |