- 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 check whether a string is in lowercase or uppercase in R?
We can use str_detect function to check whether a single string or a vector of strings is in lowercase or uppercase. Along with str_detect function, we need to use either upper or lower to check whether the string is in lowercase or uppercase and the output will be returned in TRUE or FALSE form, if the string will be in lowercase and we pass lower with str_detect function then the output will be TRUE and vice-versa.
Example
x1<-letters[1:26] x1
Output
[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"
Example
str_detect(x1,"[[:upper:]]")
Output
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [25] FALSE FALSE
Example
x2<-LETTERS[1:26] x2
Output
[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"
Example
str_detect(x2,"[[:upper:]]")
Output
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [16] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
Example
x3<-"india" x3
Output
[1] "india"
Example
str_detect(x3,"[[:upper:]]")
Output
[1] FALSE
Example
x4<-c("abc","abcd","abcde","bacdef") x4
Output
[1] "abc" "abcd" "abcde" "bacdef"
Example
str_detect(x4,"[[:upper:]]")
Output
[1] FALSE FALSE FALSE FALSE
Example
x5<-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") x5
Output
[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"
Example
str_detect(x5,"[[:upper:]]")
Output
[1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [16] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [31] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE [46] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
Example
x6<-c("alabama", "alaska", "american samoa", "arizona", "arkansas", "california", "colorado", "connecticut", "delaware", "district of columbia", "florida", "georgia", "guam", "hawaii", "idaho", "illinois", "indiana", "iowa", "kansas", "kentucky", "louisiana", "maine", "maryland", "massachusetts", "michigan", "minnesota", "minor outlying islands", "mississippi", "missouri", "montana", "nebraska", "nevada", "new hampshire", "new jersey", "new mexico", "new york", "north carolina", "north dakota", "northern mariana islands", "ohio", "oklahoma", "oregon", "pennsylvania", "puerto rico", "rhode island", "south carolina", "south dakota", "tennessee", "texas", "u.s. virgin islands", "utah", "vermont", "virginia", "washington", "west virginia", "wisconsin", "wyoming") x6
Output
[1] "alabama" "alaska" [3] "american samoa" "arizona" [5] "arkansas" "california" [7] "colorado" "connecticut" [9] "delaware" "district of columbia" [11] "florida" "georgia" [13] "guam" "hawaii" [15] "idaho" "illinois" [17] "indiana" "iowa" [19] "kansas" "kentucky" [21] "louisiana" "maine" [23] "maryland" "massachusetts" [25] "michigan" "minnesota" [27] "minor outlying islands" "mississippi" [29] "missouri" "montana" [31] "nebraska" "nevada" [33] "new hampshire" "new jersey" [35] "new mexico" "new york" [37] "north carolina" "north dakota" [39] "northern mariana islands" "ohio" [41] "oklahoma" "oregon" [43] "pennsylvania" "puerto rico" [45] "rhode island" "south carolina" [47] "south dakota" "tennessee" [49] "texas" "u.s. virgin islands" [51] "utah" "vermont" [53] "virginia" "washington" [55] "west virginia" "wisconsin" [57] "wyoming"
Example
str_detect(x6,"[[:upper:]]")
Output
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [37] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE [49] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
- Related Articles
- Convert string to lowercase or uppercase in Arduino
- How to test if a letter in a string is uppercase or lowercase using javascript?
- Check whether a character is Uppercase or not in Java
- Check whether a character is Lowercase or not in Java
- Making a Java String All Uppercase or All Lowercase.
- Conversion of whole String to uppercase or lowercase using STL in C++
- How to convert lowercase letters in string to uppercase in Python?
- Replacing upperCase and LowerCase in a string - JavaScript
- How to convert all uppercase letters in string to lowercase in Python?
- Java program to convert a string to lowercase and uppercase.
- How to create a vector with lowercase as well as uppercase letters in R?
- Program to check string is palindrome with lowercase characters or not in Python
- Converting Odd and Even-indexed characters in a string to uppercase/lowercase in JavaScript?
- How to check whether a data frame exists or not in R?
- How to Check Whether a String is Palindrome or Not using Python?

Advertisements