1

一緒に追加した臨床処置請求情報のソースが 2 つあります ( を使用rbind)。各行には、CPT フィールドと、簡単な説明を提供する CPT.description フィールドがあります。ただし、記述は 2 つのソースとは少し異なります。それらを組み合わせることができるようにしたい。そうすれば、別の単語や略語が使用されている場合でも、文字列検索を実行して探しているものを見つけることができます。

それでは、私が生成できたデータ テーブルの簡略化された表現を作成しましょう。

cpt <- c(23456,23456,10000,44555,44555)
description <- c("tonsillectomy","tonsillectomy in >12 year old","brain transplant","castration","orchidectomy")
cpt.desc <- data.frame(cpt,description)

そして、ここに私が到達したいものがあります。

cpt.wanted <- c(23456,10000,44555)
description.wanted <- c("tonsillectomy; tonsillectomy in >12 year old","brain transplant","castration; orchidectomy")
cpt.desc.wanted <- data.frame(cpt.wanted,description.wanted)

unstack や lapply(list,paste) などの関数を使用してみましたが、それは各リストの要素を貼り付けていません。私も reshape を試みましたが、説明の最初または 2 番目のバージョン、または場合によっては 3 番目のバージョンを区別するためのカテゴリ変数はありませんでした。本当に厄介な部分は、数か月または数年前に同様の問題があり、誰かがstackoverflowまたはr-helpで私を助けてくれましたが、私の人生ではそれを見つけることができません.

根本的な問題は、目の前にスプレッドシートがあると想像してください。隣接する列に同じ CPT コードを持つ 2 つまたは場合によっては 3 つの説明セルの垂直結合 (貼り付け) を行う必要があります。

この問題の解決策を探すために、どの流行語を使用する必要があったでしょうか。手伝ってくれてどうもありがとう。

4

2 に答える 2

2
sapply( sapply(unique(cpt), function(x) grep(x, cpt) ),
                       # creates sets of index vectors as a list
        function(x) paste(description[x], collapse=";") )
       # ... and this pastes each set of selected items from "description" vector
[1] "tonsillectomy;tonsillectomy in >12 year old"
[2] "brain transplant"                           
[3] "castration;orchidectomy"     
于 2012-01-17T18:30:38.617 に答える
1

を使用したアプローチを次に示しますplyr

library("plyr")
cpt.desc.wanted <- ddply(cpt.desc, .(cpt), summarise, 
  description.wanted = paste(unique(description), collapse="; "))

を与える

> cpt.desc.wanted
    cpt                           description.wanted
1 10000                             brain transplant
2 23456 tonsillectomy; tonsillectomy in >12 year old
3 44555                     castration; orchidectomy
于 2012-01-17T20:52:41.933 に答える