Rでコマンド:ベクトルの昇順・降順と指定位置に要素を挿入するコマンド例

ベクトルの昇順・降順と指定位置に要素を挿入するコマンド例です。

実行コマンドはR version 4.2.2で確認しています。

実行コマンド

詳細はコメント、コマンドのヘルプを確認してください。

###データ例#####
n <- 15
TestData <- sample(1:100, n, replace = TRUE)
#&#20869;&#23481;&#30906;&#35469;
TestData
[1] 62 46 36 37 12 71 18 24 31 80 54  3 80 41 82
######

#&#26119;&#38918;&#12539;&#38477;&#38918;&#12395;&#20006;&#12403;&#26367;&#12360;:order&#12467;&#12510;&#12531;&#12489;
#&#26119;&#38918;
TestData[order(TestData)]
[1]  3 12 18 24 31 36 37 41 46 54 62 71 80 80 82
#&#38477;&#38918;:decreasing&#12458;&#12503;&#12471;&#12519;&#12531;
TestData[order(TestData, decreasing = TRUE)]
[1] 82 80 80 71 62 54 46 41 37 36 31 24 18 12  3

#&#25351;&#23450;&#12375;&#12383;&#12505;&#12463;&#12488;&#12523;&#12398;&#20301;&#32622;&#12395;&#25968;&#20516;&#12434;&#20195;&#20837;:append&#12467;&#12510;&#12531;&#12489;
#&#20301;&#32622;&#12398;&#25351;&#23450;:after&#12458;&#12503;&#12471;&#12519;&#12531;
#&#20808;&#38957;&#12363;&#12425;6&#30058;&#30446;&#12395;99999&#12434;&#20195;&#20837;
append(TestData, 99999, after = 5)

少しでも、あなたの解析が楽になりますように!!

Prices and shipping availability may change. Please refer to the product page at time of purchase.
Content displayed on this site is provided by Amazon and may be updated or removed.
Amazon Associate, karada-good earns income through qualifying sales.
タイトルとURLをコピーしました