[R] Splitting and arranging in ascending order
Amelia Marsh
amelia_marsh08 at yahoo.com
Wed Jun 3 11:09:27 CEST 2015
Dear R forum
I have a data (actually its a big data and I am only giving part of my interest) as
my_dat = data.frame(instrument = c("EQ_0", "EQ_1", "EQ_10", "EQ_100", "EQ_2", "EQ_20", "IRS_0", "IRS_1", "IRS_10", "IRS_100", "IRS_2", "IRS_20"), mtm_value = c(23, 63, 8, 44, 68, 11, 83, 56, 73, 92, 14, 7))
> my_dat
instrument mtm_value
1 EQ_0 23
2 EQ_1 63
3 EQ_10 8
4 EQ_100 44
5 EQ_2 68
6 EQ_20 11
7 IRS_0 83
8 IRS_1 56
9 IRS_10 73
10 IRS_100 92
11 IRS_2 14
12 IRS_20 7
I need to split the first column and arrange the output in the ascending order as shown below :
instrument sr_no mtm_value
1 EQ 0 23
2 EQ 1 63
3 EQ 2 68
4 EQ 10 8
5 EQ 20 11
6 EQ 100 44
7 IRS 0 83
8 IRS 1 56
9 IRS 2 14
10 IRS 10 73
11 IRS 20 7
12 IRS 100 92
I tried to use gsub, strsplit but doesn't give me the required output.
Kindly guide
Regards
Amelia
More information about the R-help
mailing list