Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201867

Creating multiple dataframes in a loop in R

$
0
0

I am new to R and I don't know how to create multiple data frames in a loop. For example: I have a data frame "Data" with 20 rows and 4 columns:

Data <- data.frame(matrix(NA, nrow = 20, ncol = 4))
names(Data) <- c("A","B","C","D")

I want to choose the rows of Data which its values in column T are the closest values to the vector elements of X.

X = c(X1,X2,X3,X4,X5) 

Finally, I want to assign them to a separate data frames with their associated X name:

for(i in 1:length(X)){ 
data_X[i] <- data.frame(matrix(NA))  
data_X[i] <- subset(data2, 0 <= A-X[i] | A-X[i]< 0.000001 )
}

Thank you!


Viewing all articles
Browse latest Browse all 201867

Trending Articles