【问题标题】:Capitalizing text of a specific column in R's data frame大写R数据框中特定列的文本
【发布时间】:2013-08-22 08:12:57
【问题描述】:

我有一个如下所示的数据:

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

我想要做的是将第四列的文本大写。 例如,现在我们有Notch1,然后它将被转换为NOTCH1。 在 R 中这样做的方法是什么?我被这个困住了:

dat<-read.table("http://dpaste.com/1353034/plain/")

【问题讨论】:

    标签: r dataframe


    【解决方案1】:

    只需使用toupper 函数:

    R> toupper(c("a", "ab"))
    [1] "A"  "AB"
    

    对于您的数据框,您将拥有:

    dat[,4] = toupper(dat[,4])
    

    【讨论】:

    • 非常感谢。顺便说一句,我还有另一个数据看起来像这样 dpaste.com/1353038/plain 。我不想将第一列大写。但为什么这不起作用? dat&lt;-read.table("http://dpaste.com/1353038/plain/");dat[,1]=toupper(dat[,1])
    • 第二个数据集中的行名没有大写。
    • 如果是行名,则需要使用rownames(dat)
    猜你喜欢
    • 1970-01-01
    • 2020-09-07
    • 2015-12-13
    • 2017-07-28
    • 1970-01-01
    • 1970-01-01
    • 2013-09-01
    • 1970-01-01
    相关资源
    最近更新 更多