I have a data set having 3 columns Part
, Claimid
and Cost
. The dataset looks as below:
Part Claimid Cost
Part1 ID1 12
Part1 ID20 29
Part2 ID21 21
Part2 ID40 13
Part3 ID41 11
Part3 ID60 10
The cost column is a random number between 1 to 10
I am trying to run a loop for every Part
(here 3 parts) and use dplyr package to create three distinct data frames
library(dplyr)
claimid <- read.csv(file.choose(),header = TRUE)
plist <- unique(claimid$Part) ##Create the number of loops (Here 3)
for (i in plist) {
plist <- claimid %>% select(Part,Claimid) %>% filter(Part %in% i)
}
I am getting the last 20 observations when I print plist because obviously R is saving the last observation of loop.