Now I have a dataset shown below and I want to reorganize it into a single column so that it becomes 0.7539134 1.1460286 1.0238686 1.1653998 1.9950157 1.1809653 0.6834145 0.9467038 0.5653136 1.0444659 ...
Is there any way to do that? Thanks!
0.7539134 1.1460286 0.0000000 0.0000000
1.0238686 1.1653998 0.0000000 0.0000000
1.9950157 1.1809653 0.0000000 0.0000000
0.6834145 0.9467038 0.0000000 0.0000000
0.5653136 0.0000000 1.0444659 0.0000000
1.0774060 0.0000000 1.0317435 0.0000000
1.8226217 0.0000000 0.9644112 0.0000000
1.7378881 0.0000000 1.1958153 0.0000000
1.6491039 0.0000000 0.0000000 0.9218525
1.1632987 0.0000000 0.0000000 0.8771763
0.8093940 0.0000000 0.0000000 1.0241989
1.5789610 0.0000000 0.0000000 0.9722465
CodePudding user response:
subset(data.frame(v=c(t(df))), v>0)
v
1 0.7539134
2 1.1460286
5 1.0238686
6 1.1653998
9 1.9950157
10 1.1809653
13 0.6834145
14 0.9467038
17 0.5653136
19 1.0444659
21 1.0774060
23 1.0317435
25 1.8226217
27 0.9644112
29 1.7378881
31 1.1958153
33 1.6491039
36 0.9218525
37 1.1632987
40 0.8771763
41 0.8093940
44 1.0241989
45 1.5789610
48 0.9722465
CodePudding user response:
Can you try this:
data <- unlist(data, use.names = F)
#option 2:
data <- as.data.frame(unlist(data, use.names = F))