compare - look up for master data in R -


i have a problem following topic.

after using excel, workload of doing high. want r in automatic way.

i have different models of washing machines:

for every model, have data.frame required components. 1 model example

component = c("a","b","c","d","e","f","g","h","i","j") number = c(1,1,1,2,4,1,1,1,2,3) model.a= data.frame(component,quantity) 

as second information, have data.frame components, used models , in addition actual stock of these components.

component = c("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z") stock = c(100,102,103,105,1800,500,600,400,50,80,700,900,600,520,35,65,78,95,92,50,36,34,96,74,5,76)  comp.stock = data.frame(component,stock) 

the third , last inforamtion weekly production plan. have 4 weekly production plans = plan 1 months. got data.frame models of washing machines, produced in next 4 weeks , quantitiy of them.

pr.models= c("model.a","model.b","model.c","model.d") quantity= c(15000,1000,18000,16000,5000)  production= data.frame(pr.models,quantity) 

my problem now, combine these informations together, can compare models produced ( last information) components. first used components every model on own , in addition data.frame has information of components , stock.

the aim information , warning, if component stock not big enough producing models production plan.

hind: ( many same components gets used different models)

hopefully understand mean , can me problem.

thank =)

edit:

i can not follow steps:

maybe idea good, nead hind how it:

maybe possible merge every produced model (production) used components. (considered quantity producing , number need per washing machine).

my prefered output is, gert automattically dataframes every produced model needed components.

in next step should able merge these datas comp.stock see component needed how , compare stock.

have ideas on way?

maybe stupid presented way... need automatic way because there more 4k different components , more 180 different models of washing machines.

thank

the comp.stock additionally used models , quanitity ( production)

you need have model name column in first data.frame (to match production)

model.a$pr.models <- 'model.a' 

then can merge. note there 2 "quantity" columns, , don't want merge those:

merged <- merge(merge(model.a, comp.stock),production, by='pr.models') 

extra how many have on-hand after production:

transform(transform(merged, needed = quantity.x * quantity.y), = stock - needed) ##    pr.models component quantity.x stock quantity.y needed  ## 1    model.a                  1   100      15000  15000 -14900 ## 2    model.a         b          1   102      15000  15000 -14898 ## 3    model.a         c          1   103      15000  15000 -14897 ## 4    model.a         d          2   105      15000  30000 -29895 ## 5    model.a         e          4  1800      15000  60000 -58200 ## 6    model.a         f          1   500      15000  15000 -14500 ## 7    model.a         g          1   600      15000  15000 -14400 ## 8    model.a         h          1   400      15000  15000 -14600 ## 9    model.a                  2    50      15000  30000 -29950 ## 10   model.a         j          3    80      15000  45000 -44920 

if extra negative, you'll need more parts. you're deficient.

transform(transform(merged, needed = quantity.x * quantity.y), = stock - needed)$extra < 0 ##  [1] true true true true true true true true true true 

not enough of part.

as function:

not.enough.parts <- function(model, comp.stock, production) {   model$pr.models <- toupper(substitute(model))   merged <- merge(merge(model, comp.stock),production, by='pr.models')   <- transform(transform(merged, needed = quantity.x * quantity.y), = stock - needed)   retval <- extra$extra < 0   names(retval) <- extra$component   return(retval) }  not.enough.parts(model.a, comp.stock, production) ##       b    c    d    e    f    g    h       j  ## true true true true true true true true true true  

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -