Hi,
I am new to R and having problems with understanding loops in R.
basically what i want is the following
say i have a variable y with 100 observations
I want y1 = first 20 observations
y2 = second 20 obs
y3 = third 20 obs
and so on until y5
i know i can do that with
but i want to use loop as once i understand how to do this simple thing i can proceed further.
I did the following but keep getting error
Above is my code of two variables x and y.
i would not mind doing it for one variable and then i can always join them together later.
Any support is appreciated. Thank you, Max
P.S. Thanks trinker and bryangoodrich
PROBLEM SOLVED
I am new to R and having problems with understanding loops in R.
basically what i want is the following
say i have a variable y with 100 observations
I want y1 = first 20 observations
y2 = second 20 obs
y3 = third 20 obs
and so on until y5
i know i can do that with
Code:
y1 <- c(y[1:20]) and y2 <- c(y[20:40]) etc
I did the following but keep getting error
Code:
df <- list()
for(i in seq(from=0, to=80, by=20)){
for(j in seq(from=20, to=100, by=20)){
for(k in 1:5){
df[k] <- data.frame(x=c(x[i:j]), y=c(y[i:j]))
}
}
}
i would not mind doing it for one variable and then i can always join them together later.
Any support is appreciated. Thank you, Max
P.S. Thanks trinker and bryangoodrich
PROBLEM SOLVED
Last edited: