I have a data that looks like this:
GO:2000974 7,8 negative_regulation_of_pro-B_cell_differentiation Notch1 ISS
GO:2000974 7,8 negative_regulation_of_pro-B_cell_differentiation Q9W737 IEA
GO:0001768 4 establishment_of_T_cell_polarity Ccl19 IEA
GO:0001768 4 establishment_of_T_cell_polarity Ccl19 ISS
GO:0001768 4 establishment_of_T_cell_polarity Ccl21 IEA
What I want to do is to capitalize the text of the fourth column.
So for example now we have Notch1, it'll then be converted to NOTCH1.
What's the way to do it in R? I'm stuck with this:
dat<-read.table("http://dpaste.com/1353034/plain/")
The easiest way to change the case of a column name in R is by using the names() function and the tolower() (for lowercase) or toupper() (for uppercase) function. Alternatively, the rename_all() function from the dplyr package can also be used to (de)capitalize column names.
To convert a lowercase string to an uppercase string in R, use the toupper() method. The toupper() method changes the case of a string to the upper. The toupper() function takes a string as an argument and returns the uppercase version of a string.
In R, the best way to convert a text string to all lowercase characters is by using the tolower() function. This function takes a character vector or character column as input and returns the text in its transformed lowercase version.
Just use the toupper function:
R> toupper(c("a", "ab"))
[1] "A" "AB"
For your data frame, you will have:
dat[,4] = toupper(dat[,4])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With