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

∥☆過路亽.° 提交于 2019-11-29 22:58:20
data.frame[row_number, column_number] = new_value

For example, if x is your data.frame:

x[1, 4] = 5

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

iris$Sepal.Length[3]=999

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!

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
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!