Hello i'm trying to create a data frame inside a loop, this data frame should have only matching values, i'm trying to implement a logic like that:
names<- unique(list(data$costumers))
for (i in 1:length(names)) {
city <- data$city where data$costumers == names[i]
costumer <- data$costumers where data$costumers == names[i]
df <- data.frame(costumer,city)
}
Basically i'm trying to make a data frame for each unique name in the list, i don't know how to compare in a data frame, i've tried the if statement but i couldn't get it to work.
a example dataframe input would be something like that:
costumer city
Joseph WS
Edward WS
Joseph NY
so the output dataframe would be like this:
costumer city
Joseph WS
Joseph NY
and the second dataframe output would be like that:
costumer city
Edward WS
In conclusion i'm trying to get a single data frame for every unique name in the list, and that data frame should have all the rows that include that name.