vals <- expand.grid(x=seq(1000), y=seq(1000))
subset(vals, x^2 + y^2.....)
不确定从哪里开始
答案 0 :(得分:1)
# create a data.frame with all possible combos
vals <- expand.grid( x = 1:1000 , y = 1:1000 )
# calculate the z for each of these
vals$z <- sqrt( vals$x^2 + vals$y^2 )
# subset all possible combinations where z is an integer and x, y, z are <= 1000 and x < y and y < z
actuals <- subset( vals , z == round( z ) & ( x <= 1000 ) & ( y <= 1000 ) & ( z <= 1000 ) & ( x < y ) & ( y < z ) )
# answer
nrow( actuals )
# look at the first six records
head( actuals )
# plot x and y
plot( actuals$x , actuals$y )