R - joining/merging rows in one dataset -


I would like to know how to use R to merge rows into one data data.

Currently my data looks like this:

  Lesson 1 Lesson 2 Lesson 3 Lesson 4 Bob Aaba Ab ABC Robert Aba ABC ABC Fred Abd Abe Abf Martin AG Abhi Abi   

If text two and lesson 3 are the same for both of the two rows (in lines 1 and 2) I would like to create it in one line with more columns for other data

  text 1 text 1a text2 text3 text4 text4a bob robert abba abbey C ABC abd Fred na abd abe abf nah mart na ag now now NA   

I did something similar to merge into joining and joining two separate sets of data join = join (Data1, Data2, by = c ('Text2'), type = "full", match = "all")

Within a group I can not do this how to duplicate it.

I think it may be possible to use gross but I have not used it before, my attempt was:

  MyDataAgg = Total (MyData, = list By (MyData $ Text1), C)   

But when I try, I am getting an output that looks like this on the summary: < Pre> 1 -none-numeric 1 -one - numeric 2 -none-numeric

or on the structure:

  $ initial: 12505 List .. $ 1: Int 62. $ 2: Int 310 .. $ 3: int 504   

I also match two variables Just add rows using Won.

I do not think you can reshape or consolidate because: < Ol>

  • You duplicate rows that match the same key
  • You do not have the same number for each key: you should fill it with the wrong values ​​

    There is a manual attempt to use by > to process with the key, and rbind.fill together all the list together Each by step to import, one line data as the key. Creating frame (text2, text3).

      by do.call (plyr :: rbind.fill, by (Data, list ($ $ Text2, $ $ Text3), function (D) {## One line data to another row Change to Frame DD & lt; - as.data.frame (as.list (rapply (d) [, -C (2,3)], AS Chatterwriter) ## Hard part: To become lesson 1 Add 1 as text1 to 1, ## The data formed by these names is imported to join the frame. (DD) & lt; - gsub ('(text [0-9] $)', '\\ 11 ', name (DD)) ## Add key to line cobind (unique (D [2: 3]), DD)})) Text 2 text3T CST 11 text 12 text 41 text 42 1 Eba Abe Bob Robert ABC abd 2 abd Abe Fred and LT; NA & gt; AFF & LT; NA & gt; 3 abg ab martin & lt; NA & gt; Abi & lt; NA & gt;    

  • Comments

    Popular posts from this blog

    java - ImportError: No module named py4j.java_gateway -

    python - Receiving "KeyError" after decoding json result from url -

    .net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -