Assuming we have this DataFrame:
How can I change the value of column X in row "BA" ?, I know I can modify the whole row but what I want is to see how it is done since there can be dataFrame of many columns.
Thanks
Assume a data.frame
similar to your example:
df <- data.frame(x=sample(1:5, 5),
y=sample(1:5, 5))
rownames(df) <- sample(LETTERS,5)
df
x y
S 5 4
D 2 2
F 3 1
Y 4 5
X 1 3
To access any of the "cells" of this structure you can use []
indicating rows and columns, knowing the index of the row:
df[2,1]
2
df[2,1] <- 0
df[2,1]
0
Or, if the data.frame
has a rowname
(not necessarily have it) you can access using this one:
df['D',1]
0
df['D',1] <- 2
df['D',1]
1