Write an R function which takes two words as arguments/inputs -


i write r function takes 2 words arguments/inputs , returns “equal length” if number of characters equal in 2 words , “not equal length” otherwise. suppose name of function compare. work below

compare("eps568","summer") equal length compare("eps568","summera") not equal length 

i have started -

compares <- function(a,b) { if (str_length(a) == str_length(b)) return("equal length") } 

i learning r , appreciated

you need think mean "equal length" mean in memory, in counted characters, or in screen width? luckily same function deals three, need change 1 argument!!

compares <- function(a,b) { # use type="chars" number of human readible characters # use type="bytes" storage size of characters # use type="width" size of string in monospace font if (nchar(a, type="chars") == nchar(b,type="chars")) {     return("equal length") } else {     return ("not equal length") }}   > a="this string" > b="that string" > compares(a,b) [1] "equal length" > b="thatt string" > compares(a,b) [1] "not equal length" 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -