How do I change a single value in a data.frame?

前端 未结 4 1090
迷失自我
迷失自我 2020-12-08 04:20

Could anyone explain how to change a single cell in a data.frame to something else. Basically I just want to rename that one cell, not all cells which matches i

相关标签:
4条回答
  • 2020-12-08 04:34

    In RStudio you can write directly in a cell. Suppose your data.frame is called myDataFrame and the row and column are called columnName and rowName. Then the code would look like:

    myDataFrame["rowName", "columnName"] <- value
    

    Hope that helps!

    0 讨论(0)
  • 2020-12-08 04:36
    data.frame[row_number, column_number] = new_value
    

    For example, if x is your data.frame:

    x[1, 4] = 5
    
    0 讨论(0)
  • 2020-12-08 04:53

    Suppose your dataframe is df and you want to change gender from 2 to 1 in participant id 5 then you should determine the row by writing "==" as you can see

     df["rowName", "columnName"] <- value
     df[df$serial.id==5, "gender"] <- 1
    
    0 讨论(0)
  • 2020-12-08 04:56

    To change a cell value using a column name, one can use

    iris$Sepal.Length[3]=999
    
    0 讨论(0)
提交回复
热议问题