# rprogramming

1. ### How to vectorize the following loop code?

I have the following code for(i in 1:400) { if (mydata$quad[i]==1){ mydata$z[i]=rnorm(n=sum(mydata$quad[i]==1),mean=1,1) } else if (mydata$quad[i]==2){ mydata$z[i]=rnorm(n=sum(mydata$quad[i]==2),mean=9,1) } else if...
2. ### code give more variables than what I have

hello, I have the following data V1 V2 1-Dec -0.0539597263407143, -0.0511951479332808, 1-Mar 2.91833246778835, 0.549735256023383 1-Sep -0.60152265093355, 0.596134547512546 The values are in one column which is V2, I would like to separate the column V2...
3. ### what is wrong with my code.

Hello, there is a variable named quad take values from 1 to 9 ( 400 points) I'm trying to simulate a z variable as follows: fo for example if I have 30 points of quad=1 , i simulate 30 Z values with mean =0 the if I have 15 points of quad=2,I simulate 15 Z value with mean = 2 .... and so on...
4. ### what is wrong with my code

I'm generating a random numbers x,y between -10 and 10 then I create an if statement to classify each pair(x,y) in 4 quadrant in the following if statement but the column quad give me all 4 so why? x <- runif(n=400, min = -10, max = +10) y <- runif(n=400, min = -10, max = +10)...
5. ### how to (x,y) values from xy plane in R

Hello, I would like to generate random points on the x-y plane, for example let's set -10 < X < 10, -10 < Y < 10, and n = 400 how can I do that?
6. ### Combine two epidemiology netcdf files in R

Hello, I have 2 netCDF files (each .nc file has 4 variables: Susceptible, Infected, Recovered and Inhabitable. The dimension of each variable is 64 x 88). I would like to merge these 2 files using R into a single netCDF file such that the merged file will stack separately Susceptible from the...