Replace/add values to column in dataframe x looking at values in data frame y in R
temp file or X is a very big data frame
1 idname 3 unit
aa jhn cc NA
dd m234 ff NA
gg cind ii NA
nn ....
pp.....
map file or Y is a small data frame
name id contact address
john jhn J123 J
Mary Mry M234 M
My condition is
for(i in 1:length(x$1)) {
if (X$2==Y$alt_name1 || X$2==Y$alt_name2 || X$2==Y$alt_name3)
X$name[i] = Y$name[i]
}
That is, If the values in any of the columsn in Y except Y$name matches with value in X$2 corresponding Y$name should be added in exact row of X$name
Is there any efficient way to carry out this operation ? x had some millions of rows and y has say 4 rows.
Any help is very much appreciated.
What i have now is
for (i in 1: length(tempFile$unit)) {
for (j in 1: length(mapFile$Name)) {
if (tempFile$idname[i]==mapFile$id[j])
elseif (tempFile$idname[i]==mapFile$contact[j])
elseif (tempFile$idname[i]==mapFile$address[j])
tempFile$unit[i] <- mapFile$Name[j]
}
}