![]() |
VOOZH | about |
In this article, we will discuss how to repeat the character string N times in the R programming language. Character string means a set of characters .
Example:
"Hello Geek","Python","Languages_Python" are some examples
This function used to give n replicas from the character string
Syntax:
replicate(N, "string")
where,
Example: R program to repeat the character string N times using replicate
Output:
[1] "Hello_Geek" "Hello_Geek"
[1] "-----"
[1] "Python" "Python" "Python" "Python" "Python" "Python" "Python" "Python"
[9] "Python" "Python"
[1] "-----"
[1] "java" "java" "java"
[1] "-----"
[1] "dbms" "dbms" "dbms" "dbms"
[1] "-----"
[1] "sql" "sql" "sql" "sql" "sql"
[1] "-----"
[1] "big data" "big data" "big data" "big data" "big data" "big data" "big data"
This function works similar to replicate .
Syntax:
rep( "string",N)
Example: R program that repeats character String N times using rep
Output:
[1] "Hello_Geek" "Hello_Geek"
[1] "-----"
[1] "Python" "Python" "Python" "Python" "Python" "Python" "Python" "Python"
[9] "Python" "Python"
[1] "-----"
[1] "java" "java" "java"
[1] "-----"
[1] "dbms" "dbms" "dbms" "dbms"
[1] "-----"
[1] "sql" "sql" "sql" "sql" "sql"
[1] "-----"
[1] "big data" "big data" "big data" "big data" "big data" "big data" "big data"
This paste is used to organize the repeated strings in the correct way, It will separate the strings with the given delimiter.
Syntax:
paste(replicate(N, "string"), collapse = "delimiter")
where,
Example: R program to repeat the character strings using paste command
Output:
[1] "Geek--Geek"
[1] "-----"
[1] "Python,Python"
This function is used to get the N character strings in a single string.
Syntax:
strrep( "string",N)
Example: R program to get N character strings using strrep() function
Output:
[1] "Hello_GeekHello_Geek"
[1] "-----"
[1] "PythonPythonPythonPythonPythonPythonPythonPythonPythonPython"
[1] "-----"
[1] "javajavajava"
[1] "-----"
[1] "dbmsdbmsdbmsdbms"
[1] "-----"
[1] "sqlsqlsqlsqlsql"
[1] "-----"
[1] "big databig databig databig databig databig databig data"