I would like to find a specific value in a column of a data frame and then replaced by whatever I want.
For example, I have a data frame with the name of cities (column 1) and the frequency (column 2). But some of the cities have different district thus R see them like different cities because they have not the same row name.
Example:
--> I have:
City Freq
1 Paris 01 69
2 Paris 03 60
3 Paris 15 12
4 Paris 20 2
5 Toulouse 60
6 Paris 15
7 Lille 12
--> I would like:
City Freq
1 Paris 69
2 Toulouse 60
3 Lille 12
I tried to use the gsub function but I don't know how to deal with it. Also I tried some if statement but I failed. I really tried to find some answers before posting something but the examples I have found are simplier and involved only the change of all the column (etc...).
Thank you for helping me!
Here some informations about my data:
dput(droplevels(head(data)))
structure(list(City = structure(c(1L, 4L, 3L, 5L, 2L, 6L), .Label = c("PARIS", "PARIS 13", "PARIS 15", "PARIS 16", "PARIS 18", "PARIS 20"), class = "factor"), Freq = c(8859L, 3843L, 3583L, 2651L, 2586L, 2464L)), .Names = c("City", "Freq"), row.names = c(19380L, 19396L, 19395L, 19398L, 19393L, 19400L), class = "data.frame")
You can modify the 'City' column using
sub
data