請問r語言sort函數中index是什么意思?
5 回答

慕沐林林
TA貢獻2016條經驗 獲得超9個贊
是一邏輯值,決定索引向量是否也要返回。注意只對某些情況有效。查到的參數說明如下:
index.return logical indicating if the ordering index vector should be returned as well; this is only available for a few cases, the default na.last = NA and full sorting of non-factors.

慕村9548890
TA貢獻1884條經驗 獲得超4個贊
1、sort()函數描述:對給定區間所有元素進行排序。sort()函數語法:sort(begin,end),表示一個范圍。2、sort()函數舉例:
123456789 | #include <algorithm> #include <iostream> using namespace std; main() { int a[11]={2,4,8,5,7,1,10,6,9,3}; //a的長度=待排數據個數+1 sort(a,a+10); //對[a,a+10)排序 for ( int i=0;i<10;++i) cout<<a[i]<<endl; } |

縹緲止盈
TA貢獻2041條經驗 獲得超4個贊
排序(sort)
語法:
void sort();
void sort( Comp compfunction );
sort()函數為鏈表排序,默認是升序。如果指定compfunction的話,就采用指定函數來判定兩個元素的大小

尚方寶劍之說
TA貢獻1788條經驗 獲得超4個贊
例如
12 | substr( "abcdef" , 2 , 4 ) # 提取第2到第4位置的元素 [ 1 ] "bcd" |
獲得位置 應該用 grep( )
1234567 | a<- LETTERS [ 1 : 8 ] #輸出的 #> a #[1] "A" "B" "C" "D" "E" "F" "G" "H" grep( "D" ,a,value= F ) # 結果 [1] 4 D在a 中的第四個 |
# 缺點是這函數一次只能提取一個
#針對這個問題可以設計一個循環 函數 一次可以提取index里面的多個
123456789101112 | f<-function(index,x){ a<-c() for (i in index){ a[i]<-grep(i,x,value= F ) } return (a) } #測試: x<-a index<- c( "A" , "D" , "H" ) f(index,x) |
結果截圖:
- 5 回答
- 0 關注
- 1586 瀏覽
添加回答
舉報
0/150
提交
取消