Hi I have a simple function:
same_picking <- function(cena){
data_model2$price_model2 <- 0.6 + cena * data_model2$item_SKU + 0.4
}
I would like the output to be rewritten in a column of a data.frame.
currently, because I still did not get the first writing of a function the column is still filled with NAs.. but I would like that after every run of a function the values would be rewriten in theat column.
count_code sifra item_SKU price_model2
281 0421 2 NA
683 0499 5 NA
903 0654 3 NA
7390 0942 3 NA
2778 0796 5 NA
2778 0796 7 NA
7066 0907 83 NA
281 0421 2 NA
I have tried with the comands: data.frame and within... but it got me nowhere.
I would appraciate the help. Andraz
Solution:
same_picking <- function(cena){
data_model2$price_model2 <<- 0.6 + cena * data_model2$item_SKU + 0.4
}
<<- operator allows you to access the object from the ouside. Very clean :)
data_model1, data_model2$price_model2. Do you have two datasets? Perhaps you needdata_model2$price_model2 <- 0.6 + cena * data_model2$item_SKU + 0.4; data_model2Also it is better to use[instead of$data_model2