Convert Vector Elements to Uppercase in R with toupper()
In R, you can use the 'toupper()' function to convert all the elements of a vector to uppercase. Here is an example:
# Create a vector with lowercase words
words <- c('apple', 'banana', 'cherry')
# Convert all the elements to uppercase
upper_words <- toupper(words)
# Print the result
print(upper_words)
Output:
[1] 'APPLE' 'BANANA' 'CHERRY'
In the above code, the 'toupper()' function is applied to the 'words' vector, and the result is stored in the 'upper_words' vector. The 'print()' function is then used to display the transformed vector.
原文地址: https://www.cveoy.top/t/topic/g3wl 著作权归作者所有。请勿转载和采集!