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 it. I can´t use the edit()
command because it will screw up my script since im using the data.frame
on several occasions.
Thanks in advance
data.frame[row_number, column_number] = new_value
例如,如果x
是您的data.frame:
x[1, 4] = 5
要使用列名更改单元格值,可以使用
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.