2016-05-12 4 views
0

ユニークな値を取得しようとすると、次の結果が得られます。私はこのようなアルファベットの代わりに、行番号を持つ別の行にそれぞれの結果を取得できますか形式R出力をそれぞれの結果を別々の行に、アルファベットを行識別子として取得

unique(big1.csv[grepl("c1", tolower(big1.csv$Remarks)) &grepl("arm", tolower(big1.csv$Remarks)) 
          &grepl("back", tolower(big1.csv$Remarks)) 
          , ]$New_Remarks) 

[1] "c1 noted to back and arms, dose repeated"    "c1 noted to back of arms and flanks, dose repeated"  
[3] "c1 noted to arms and back, dose repeated"    "c1 noted to back and upper arms, dose repeated"   
[5] "c1 noted to back of arms, dose repeated"    "c1 noted to back and chest, dose repeated"    

?またはローマ数字?

[a] "c1 noted to back and arms, dose repeated" 
[b] "c1 noted to back of arms and flanks, dose repeated"  
[c] "c1 noted to arms and back, dose repeated" 
[d] "c1 noted to back and upper arms, dose repeated"   
[e] "c1 noted to back of arms, dose repeated" 
[f] "c1 noted to back and chest, dose repeated" 
+1

あなたはdata.frameし、結果を保存したりdata.table、あなたは( 'てみたいものは何でもしてID列を追加してみてくださいすることができますLETTERS' )、次にCSVとしてエクスポートします。 –

+0

こんにちはM.D、私は変数bにその一意の行を保存し、次のコード、b = as.data.frame(ID = LETTERS、b)を使用しました。それは私に別々の行で結果を与えましたが、文字の代わりに "["& "]"のない行番号を得ました。助言がありますか? – andy

答えて

1

おそらくあなたは、データフレームにIDをカスタムメイドであなたのunique.stringsを組み合わせることができます。

unique.strings <- unique(big1.csv[grepl("e1", tolower(big1.csv$Remarks)) &grepl("arm", tolower(big1.csv$Remarks)) 
         &grepl("back", tolower(big1.csv$Remarks)) 
         , ]$New_Remarks) 
df <- data.frame(ID = paste0("[", letters[1:length(unique.strings)], "]"), unique.strings) 
+0

ありがとうzyurnaidi私はdf < - data.frame(ID = paste0( "["、letters [1:dim(unique.strings)[1]]、 "]")、unique.stringsを使用しました。 – andy

+0

はい。それはよかっただろう。 'unique.strings'が文字ベクトルであると仮定しているので、私は' length'の少し異なる関数を使ってコードを編集します – zyurnaidi

2

私はこの例を参照してください、あなたはrownamesが必要だと思う:

unique.strings <- c("xxx", "yyy", "zzz") 

df <- data.frame(unique.strings) 
rownames(df) <- make.unique(letters[1:nrow(df)]) 

df 
# unique.strings 
# a   xxx 
# b   yyy 
# c   zzz 
関連する問題