- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to print string vectors vertically in R?
To print string vectors vertically in R, we can follow the below steps −
- First of all, create a vector.
- Then, use cat function to print the vector vertically.
Example 1
Let's create a vector as shown below −
Alphabets<-LETTERS[1:26] Alphabets
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O" "P" "Q" "R" "S" [20] "T" "U" "V" "W" "X" "Y" "Z"
Print the vector vertically
Using cat function to print the Alphabets vector in vertical form −
Alphabets<-LETTERS[1:26] cat(paste("\t",Alphabets,"
",sep ="\""))
Output
“A” “B” “C” “D” “E” “F” “G” “H” “I” “J” “K” “L” “M” “N” “O” “P” “Q” “R” “S” “T” “U” “V” “W” “X” “Y” “Z”
Example 2
Let's create a vector as shown below −
US_States<-c("AK", "AL", "AR", "AS", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "GU", "HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN", "MO", "MP", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UM", "UT", "VA", "VI", "VT", "WA", "WI", "WV", "WY") US_States
On executing, the above script generates the below output(this output will vary on your system due to randomization) −
[1] "AK" "AL" "AR" "AS" "AZ" "CA" "CO" "CT" "DC" "DE" "FL" "GA" "GU" "HI" "IA" [16] "ID" "IL" "IN" "KS" "KY" "LA" "MA" "MD" "ME" "MI" "MN" "MO" "MP" "MS" "MT" [31] "NC" "ND" "NE" "NH" "NJ" "NM" "NV" "NY" "OH" "OK" "OR" "PA" "PR" "RI" "SC" [46] "SD" "TN" "TX" "UM" "UT" "VA" "VI" "VT" "WA" "WI" "WV" "WY"
Print the vector vertically
Using cat function to print the Alphabets vector in vertical form −
US_States<-c("AK", "AL", "AR", "AS", "AZ", "CA", "CO", "CT", "DC", "DE", "FL", "GA", "GU", "HI", "IA", "ID", "IL", "IN", "KS", "KY", "LA", "MA", "MD", "ME", "MI", "MN", "MO", "MP", "MS", "MT", "NC", "ND", "NE", "NH", "NJ", "NM", "NV", "NY", "OH", "OK", "OR", "PA", "PR", "RI", "SC", "SD", "TN", "TX", "UM", "UT", "VA", "VI", "VT", "WA", "WI", "WV", "WY") cat(paste("\t",US_States,"
",sep ="\""))
Output
"AK" "AL" "AR" "AS" "AZ" "CA" "CO" "CT" "DC" "DE" "FL" "GA" "GU" "HI" "IA" "ID" "IL" "IN" "KS" "KY" "LA" "MA" "MD" "ME" "MI" "MN" "MO" "MP" "MS" "MT" "NC" "ND" "NE" "NH" "NJ" "NM" "NV" "NY" "OH" "OK" "OR" "PA" "PR" "RI" "SC" "SD" "TN" "TX" "UM" "UT" "VA" "VI" "VT" "WA" "WI" "WV" "WY"
- Related Articles
- How to print the vector elements vertically in R?
- How to concatenate string vectors separated with hyphen in R?
- How to concatenate numerical vectors and a string to return a string in R?
- How to find different elements between two string vectors in R?
- How to remove spaces at the end in string vectors in R?
- How to match two string vectors if the strings case is different in both the vectors in R?
- How to create combinations for each string values in two vectors in R?
- How to find the number of common words between two string vectors in R?
- How to combine array of vectors in R?
- Print Words Vertically in Python
- How to concatenate two or more vectors in R?
- How to create combination of multiple vectors in R?
- How to multiply two vectors in R as in mathematics?
- How to find pairwise maximum among multiple vectors in R?
- How to find the union of two vectors in R?

Advertisements