Changing the Increment of Sequences

I made the following grid in R:

n <- 3
 my_grid <- expand.grid(i1 = 1:n, i2 = 1:n, i3 = 1:n) 
my_grid$final_value = with(my_grid, sin(i1) + cos(i2) + i3)
 head(my_grid)

In this grid, the increments are by "whole numbers",e.g. 1,2,3, etc. Is it possible to use the "expand.grid" statement and change the increment of the grid to "0.1"? E.g. 1,1.1,1.2...1.8,1.9,2, 2.1, 2.2....2.8, 2.9,3 ?

Thanks

Something like:

n <- 3
 my_grid <- expand.grid(i1 = seq(from=1, to=n, by=0.1), i2 = 1:n, i3 = 1:n) 
1 Like

thank you so much! This works perfectly!

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.