Elbert

I would like to ask, how to set a value in array using looping. say like this

```
a<-3
b<-4
for( i in 1:5)
{
x[i] <- cbind(a*i, b*i)
}
```

but i always get error saying : In x[i] <- cbind(a * i, b * i) : number of items to replace is not a multiple of replacement length. I used "paste" but seems it's not the solution. What is the problem ? If it were solved, can I get the value by using ; for example x[2][,2] to get the value of b * 2 ? thank you

Yo B.

You can do it this way :

```
a <- 3
b <- 4
i <- 1:5
x <- cbind(a*i, b*i)
```

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at

- Prev: Summed area table in GLSL and GPU fragment shader execution
- Next: How to synchronize multiple Alamofire requests

*1*### R number of items to replace is not a multiple of replacement length

*2*### R error: "number of items to replace is not a multiple of replacement length"

*3*### R number of items to replace is not a multiple of replacement length / results however correct

*4*### Error in R :Number of items to replace is not a multiple of replacement length

*5*### Error number of items to replace is not a multiple of replacement length

*6*### R: number of items to replace is not a multiple of replacement

*7*### Why do I get "number of items to replace is not a multiple of replacement length"

*8*### RStudio Shiny Error - number of items to replace is not a multiple of replacement length

*9*### RMOA predict error (number of items to replace is not a multiple of replacement length)

*10*### number of items to replace is not a multiple of replacement length for a data frame

*11*### Nested loops in R multiple replacement length

*12*### String array length printed instead of the Number of Array Items in C++

*13*### Populate limited number of items in array, but keep array length - mongoose

*14*### Length of items by field in an array

*15*### Regex Replacement with Repetition, How do I replace each "\r\n" in X number of occurrences of ".+?\r\n"?

*16*### Replace multiple Regex Matches each with a different replacement

*17*### R Error: replacement diagonal has wrong length

*18*### R Error: replacement diagonal has wrong length

*19*### Error: Replacement has length zero R

*20*### 'replacement has length zero' error in R

*21*### Linux, find replace on a folder of files using a list of items for replacement?

*22*### Array of Multiple items in Swagger

*23*### preg_replace to preg_replace_callback with an array as replacement

*24*### preg_replace to preg_replace_callback with an array as replacement

*25*### Counting number of items in multiple groups

*26*### byte array with variable length to number

*27*### Replace the value with "X" with same number of length

*28*### Merge equal items with multiple lists but different length

*29*### Reduce array to set number of items?

## Comments