Reputation: 65
I have the following data :
as.integer(datIn$Measurement.location)
myfunctionSD <- function(mydata) { return(sd(mydata,na.rm=TRUE))}
Alltubes <- tapply(datIn$Material.loss.interval,list(as.factor(datIn$Measurement.location),as.factor(datIn$Tube.number)),myfunctionSD)
From this I get the following output table:
1 2 3 4 5 6
1 0.8710740 0.7269928 0.8151022 0.6397234 0.8670634 0.7042107
10 NA 0.8075675 NA NA NA NA
11 0.6977951 NA 1.0984465 1.1148588 1.2156506 0.9620030
12 NA 0.5986758 NA NA NA NA
13 0.8386249 NA 0.8398164 0.8833184 1.2469221 1.0070322
14 NA 0.5109903 NA NA NA NA
15 NA NA NA 0.9391486 1.3571094 0.8375686
16 NA 0.5761583 NA NA NA NA
17 NA NA NA NA 1.0100850 0.7171070
19 NA NA NA NA 0.5913518 NA
3 0.5580579 0.6106961 0.8971073 0.7046614 0.8456784 0.8001571
4 NA 0.7228325 NA NA NA NA
5 0.9318795 NA 0.8961706 0.7753733 0.5915633 1.0471933
6 NA 0.5968613 NA NA NA NA
7 0.7674944 NA 0.7196781 0.8543926 0.7778685 0.8697442
8 NA 0.6283008 NA NA NA NA
9 1.3687895 NA 0.8815196 1.1723445 1.1589998 0.8194962
How do I rearrange the row numbers in the correct numeric order, so from 1 to 19 so I can plot it correctly?
Hope someone can help me.
Upvotes: 1
Views: 834
Reputation: 15458
df2 is your data frame
df2[order(as.numeric(rownames(df2))),]
X1 X2 X3 X4 X5 X6
1 0.8710740 0.7269928 0.8151022 0.6397234 0.8670634 0.7042107
3 0.5580579 0.6106961 0.8971073 0.7046614 0.8456784 0.8001571
4 NA 0.7228325 NA NA NA NA
5 0.9318795 NA 0.8961706 0.7753733 0.5915633 1.0471933
6 NA 0.5968613 NA NA NA NA
7 0.7674944 NA 0.7196781 0.8543926 0.7778685 0.8697442
8 NA 0.6283008 NA NA NA NA
9 1.3687895 NA 0.8815196 1.1723445 1.1589998 0.8194962
10 NA 0.8075675 NA NA NA NA
11 0.6977951 NA 1.0984465 1.1148588 1.2156506 0.9620030
12 NA 0.5986758 NA NA NA NA
13 0.8386249 NA 0.8398164 0.8833184 1.2469221 1.0070322
14 NA 0.5109903 NA NA NA NA
15 NA NA NA 0.9391486 1.3571094 0.8375686
16 NA 0.5761583 NA NA NA NA
17 NA NA NA NA 1.0100850 0.7171070
19 NA NA NA NA 0.5913518 NA
Upvotes: 1
Reputation: 61214
Something like this...
> Alltubes[sort(as.numeric(rownames(Alltubes))), ]
Upvotes: 1