how can I change a single value of a DataSet in R?

1

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

    
asked by lcguemes 31.10.2018 в 22:13
source

1 answer

2

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
    
answered by 01.11.2018 в 02:36