0

I will try to keep it simple. I have a dataset with 50407 rows and 422 columns. Within this 50k rows I search for some data points which comes to 346 rows and 422 columns. I would like to ID the 346 rows. So I added a new column called MODE and put in A. So after that I have 346 rows and 423 column. Then I would like to add the 347 rows back to the 50407 with the new column MODE.

maindata <- data.frame(main_set)
cutdata <- data.frame(cut_set)
data_set <- rbind(maindata, cutdata)
add_data <- unique(data_set)

when I do as you may guess because of the new column there all unique now so data does not gets cut.

So I'm not sure what to try now. whatever help you can give.

example main
column0|column1|column2|column3|MODE
     4 |  83   |   23  |   863 | B
    53 |  26   |   9   |   153 | B
    33 |  66   |   91  |   693 | B
     6 |  87   |   27  |   863 | B
    57 |  27   |   9   |   153 | B
    37 |  67   |   97  |   693 | B

example cut
column0|column1|column2|column3|MODE
     6 |  87   |   27  |   863 | A
    57 |  27   |   9   |   153 | A
    37 |  67   |   97  |   693 | A

rbind
column0|column1|column2|column3|MODE
     4 |  83   |   23  |   863 | B
    53 |  26   |   9   |   153 | B
    33 |  66   |   91  |   693 | B
     6 |  87   |   27  |   863 | B
    57 |  27   |   9   |   153 | B
    37 |  67   |   97  |   693 | B
     6 |  87   |   27  |   863 | A
    57 |  27   |   9   |   153 | A
    37 |  67   |   97  |   693 | A

Idea answer

column0|column1|column2|column3|MODE
     4 |  83   |   23  |   863 | B
    53 |  26   |   9   |   153 | B
    33 |  66   |   91  |   693 | B
     6 |  87   |   27  |   863 | A
    57 |  27   |   9   |   153 | A
    37 |  67   |   97  |   693 | A
orthoeng2
  • 140
  • 1
  • 6
  • 3
    Welcome to SO. In order for you to attract the best possible answers to your question, it is best to include a minimal reproducible example in your post, along with the desired result. Good links for learning how to do that are [ask], [mcve], and [How to make a great R reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – Rich Scriven Jan 27 '16 at 16:34

1 Answers1

1

You could use dplyr to manipulate the data. Lets say you want to mark the cars in mtcars according to their number of cylinders and horsepower:

require(dplyr)
mtcars %>% group_by(cyl) %>% mutate(MODE = ifelse(hp > 180,"A","B")) %>% data.frame()

This way all cars are grouped by their cylinder number and tagged with "A" if the horsepower is greater than 180 and with "B" if hp is lower than 180.

count
  • 1,328
  • 9
  • 16
  • The trailing pipe to `data.frame` can also be changed to pipe to `ungroup` if you are just trying to remove the groups. – steveb Jan 27 '16 at 17:22