i am trying to use data table package. i want to find out a way to create a new column based on specific conditions in 3 variable which is related to a calculation.
#this is my dataset
dput(dt[1:5])
structure(list(cashtype = c("", "", "", "", ""), quantity = c(1200000,
1400000, 2400000, 2500000, 810000), price_mid = c(100.0385, 102.5583,
92.7059, 108.515, 113.8505), value_mid = c(1200462.3, 1189302.74,
2224941.6, 2712875, 922189.41), currency_price = c("GBP", "EUR",
"GBP", "GBP", "GBP"), currency_value = c("GBP", "GBP", "GBP",
"GBP", "GBP")), class = c("data.table", "data.frame"), row.names = c(NA,
-5L), .internal.selfref = <pointer: 0x15f28c0>)`
I need to check the calculations for this large dataset. not all the numbers add up. but i have a way to check so. which is the 'value_mid' column divided by 'quantity' multiplied by 100. this should add up to the price_mid column. using the column valid to check. after this i would like to ideally turn the 'valid' observations into "True" that match 'price_mid' & those that do not into "False".
dt[,valid:= (value_mid/quantity)*100]
I'm not to sure how to use a ifelse function within datatable. was finding it confusing. thanks
Aucun commentaire:
Enregistrer un commentaire