0

I want to take data from one set and enter it into another empty set.

So, for example, I want to do something like:

if ([i,x] > 9){
   new_data$House[y,x] <- data[i,2]
}

but I want to do it over and over, creating new rows in new_data. How do I keep adding data to new_data and overriding/saving the new row?

Essentially, I just want to know how to "grow" an empty data set. Please ignore any errors in the code, it is just an example and I am still working on other details.

Thanks

Jacky
  • 37
  • 6

1 Answers1

0

If you are using r language, I presume you are looking for rbind:

new_data = NULL # define your new dataset

for(i in 1:nrow(data)) # loop over row of data
{
    if(data[i,x] > 9) # if statement for implementing a condition
    {
       new_data = rbind(new_data,data[i,2:6]) # adding values of the row i and column 2 to 6
    }
} 

At the end, new_data will contain as many rows that satisfy the if statement and each row will contain values extracted from column 2 to 6.

If it is what you are looking for, there is various ways to do that without the need of a for loop, as an example:

new_data = data[data[i,x]>9,2:6]

If this answer is not satisfying for you, please provide more details in your question, include a reproducible example of your data and the expected output

dc37
  • 15,840
  • 4
  • 15
  • 32