I've generated a dataset to get all 3 digit ABC numbers that are equal to A + B^2 + C^3.
So what I've done is:
define a to be 1:9 define b to be 0:9 define c to be 0:9
d <- expand.grid(a, b, c)
I then added two more columns column "Number" which is created via 100*a + 10*b + c, and column "sum" which is created via the formula a + b^2 + c^3.
Now I couldn't write any if or which such that it prints or lists all the entries of which Number and sum values are equal.
So my grid (5 variables) is called d3.
I want something like;
if (d3$Number == d3$sum) { list(d3$Number) }
But I cannot do this because this statement doesn't work when comparing two variables and I couldn't find any solution using the keywords I could think of.
I also need to write an c++ package on Rcpp package to do this for 6 digits but that is another problem for later.
Thanks all!
Aucun commentaire:
Enregistrer un commentaire