Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Capitalizing text of a specific column in R's data frame

Tags:

dataframe

r

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/")
like image 396
neversaint Avatar asked Aug 22 '13 08:08

neversaint


People also ask

How do you capitalize values in a column in R?

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.

How do you capitalize data in R?

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.

How do I change all values in a column to lowercase in R?

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.


1 Answers

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])
like image 197
csgillespie Avatar answered Oct 17 '22 07:10

csgillespie