How to rotate isolines in contour plot and make colours discrete - gnuplot

I am trying to plot the result of an experiment with the following
set encoding iso_8859_1
set key right top font "Helvetica,17"
# set key left top font "Helvetica,18"
# set key at 100,1.25 bottom center font "Helvetica,17"
# set ylabel "Percentage of non-completed batches" font "Helvetica,18"
set ylabel "Extra frames" font "Helvetica,18"
set xlabel "Dispersion [%]" font "Helvetica,18"
unset key
set xtics font "Helvetica,18"
set ytics font "Helvetica,18"
set terminal postscript eps enhanced color #size 6.5in,3in #"Helvetica" 16 #
set output "contour.eps"
set palette rgbformulae 33,13,10
$complete << EOD
0 0 2.000400080016007
0 5 1.160696417850715
0 10 0.48028817290374226
0 15 0.5003001801080598
0 20 0.5201040208041574
0 25 0.9803921568627416
0 30 2.360472094418886
0 35 14.942988597719541
0 40 28.6972183309986
0 45 34.78783026421137
0 50 39.771817453963166
0 55 47.28837302381429
0 60 62.3124624924985
0 65 74.25940752602081
0 70 79.45589117823565
0 75 86.93477390956382
0 80 91.47829565913183
0 85 94.21884376875374
0 90 95.75915183036608
0 95 97.47949589917984
0 100 98.33966793358671
20 0 0
20 5 0
20 10 0
20 15 0
20 20 0
20 25 0
20 30 0
20 35 0
20 40 0
20 45 0
20 50 0
20 55 0
20 60 0.22022022022022414
20 65 0.26026026026025884
20 70 1.6012810248198561
20 75 7.301460292058415
20 80 13.165266106442575
20 85 22.03321993195918
20 90 33.13325330132053
20 95 42.997198879551824
20 100 52.041633306645316
40 0 0
40 5 0
40 10 0
40 15 0
40 20 0
40 25 0
40 30 0
40 35 0
40 40 0
40 45 0
40 50 0
40 55 0
40 60 0
40 65 0.020016012810253336
40 70 0.08006405124099114
40 75 1.9619619619619666
40 80 7.703081232492992
40 85 12.264905962384953
40 90 22.168867547018813
40 95 31.81909145487293
40 100 43.17727090836334
60 0 0
60 5 0
60 10 0
60 15 0
60 20 0
60 25 0
60 30 0
60 35 0
60 40 0
60 45 0
60 50 0
60 55 0
60 60 0
60 65 0
60 70 0.02000400080015563
60 75 0.7201440288057581
60 80 5.484387510008004
60 85 9.263705482192874
60 90 18.170902541524914
60 95 28.665733146629325
60 100 38.21528611444578
80 0 0
80 5 0
80 10 0
80 15 0
80 20 0
80 25 0
80 30 0
80 35 0
80 40 0
80 45 0
80 50 0
80 55 0
80 60 0
80 65 0
80 70 0
80 75 0.4604604604604656
80 80 4.02080416083217
80 85 7.78155631126225
80 90 15.835835835835832
80 95 25.690276110444177
80 100 34.90792634107286
100 0 0
100 5 0
100 10 0
100 15 0
100 20 0
100 25 0
100 30 0
100 35 0
100 40 0
100 45 0
100 50 0
100 55 0
100 60 0
100 65 0
100 70 0
100 75 0.16009605763458445
100 80 3.220644128825767
100 85 7.145716573258609
100 90 13.985594237695075
100 95 22.83370022013208
100 100 32.0328131252501
120 0 0
120 5 0
120 10 0
120 15 0
120 20 0
120 25 0
120 30 0
120 35 0
120 40 0
120 45 0
120 50 0
120 55 0
120 60 0
120 65 0
120 70 0
120 75 0.08001600320064473
120 80 2.8411364545818274
120 85 5.841168233646732
120 90 12.782556511302257
120 95 21.73303982389434
120 100 30.550550550550547
140 0 0
140 5 0
140 10 0
140 15 0
140 20 0
140 25 0
140 30 0
140 35 0
140 40 0
140 45 0
140 50 0
140 55 0
140 60 0
140 65 0
140 70 0
140 75 0.02000800320127727
140 80 2.601040416166467
140 85 5.584467574059248
140 90 12.027216329797874
140 95 20.12012012012012
140 100 29.372871168102588
160 0 0
160 5 0
160 10 0
160 15 0
160 20 0
160 25 0
160 30 0
160 35 0
160 40 0
160 45 0
160 50 0
160 55 0
160 60 0
160 65 0
160 70 0
160 75 0.02000800320127727
160 80 1.8021625951141318
160 85 5.321064212842563
160 90 10.024009603841533
160 95 18.60744297719088
160 100 29.040656919687557
180 0 0
180 5 0
180 10 0
180 15 0
180 20 0
180 25 0
180 30 0
180 35 0
180 40 0
180 45 0
180 50 0
180 55 0
180 60 0
180 65 0
180 70 0
180 75 0.020012007204317506
180 80 1.8603720744148844
180 85 4.90196078431373
180 90 10.864345738295322
180 95 18.687474989996
180 100 27.09083633453382
200 0 0
200 5 0
200 10 0
200 15 0
200 20 0
200 25 0
200 30 0
200 35 0
200 40 0
200 45 0
200 50 0
200 55 0
200 60 0
200 65 0
200 70 0
200 75 0.020012007204317506
200 80 1.3605442176870763
200 85 4.520904180836172
200 90 9.601920384076813
200 95 17.363472694538906
200 100 26.485297059411884
220 0 0
220 5 0
220 10 0
220 15 0
220 20 0
220 25 0
220 30 0
220 35 0
220 40 0
220 45 0
220 50 0
220 55 0
220 60 0
220 65 0
220 70 0
220 75 0.020012007204317506
220 80 1.241489787745298
220 85 4.520904180836172
220 90 8.805283169901944
220 95 17.18687474989996
220 100 25.825165033006602
240 0 0
240 5 0
240 10 0
240 15 0
240 20 0
240 25 0
240 30 0
240 35 0
240 40 0
240 45 0
240 50 0
240 55 0
240 60 0
240 65 0
240 70 0
240 75 0
240 80 1.0806483890334229
240 85 4.740948189637928
240 90 8.30332132853141
240 95 16.643328665733147
240 100 25.245049009801956
260 0 0
260 5 0
260 10 0
260 15 0
260 20 0
260 25 0
260 30 0
260 35 0
260 40 0
260 45 0
260 50 0
260 55 0
260 60 0
260 65 0
260 70 0
260 75 0
260 80 1.040208041608326
260 85 4.181672669067627
260 90 8.641728345669131
260 95 15.606242496998801
260 100 25.415249149489693
280 0 0
280 5 0
280 10 0
280 15 0
280 20 0
280 25 0
280 30 0
280 35 0
280 40 0
280 45 0
280 50 0
280 55 0
280 60 0
280 65 0
280 70 0
280 75 0
280 80 0.9603841536614643
280 85 3.8007601520304024
280 90 7.74464678807284
280 95 15.395395395395395
280 100 24.16966786714686
300 0 0
300 5 0
300 10 0
300 15 0
300 20 0
300 25 0
300 30 0
300 35 0
300 40 0
300 45 0
300 50 0
300 55 0
300 60 0
300 65 0
300 70 0
300 75 0
300 80 0.860860860860857
300 85 3.923923923923922
300 90 7.401480296059216
300 95 14.811849479583671
300 100 25.27516509905944
320 0 0
320 5 0
320 10 0
320 15 0
320 20 0
320 25 0
320 30 0
320 35 0
320 40 0
320 45 0
320 50 0
320 55 0
320 60 0
320 65 0
320 70 0
320 75 0
320 80 1.00040016006403
320 85 3.7222333400039997
320 90 7.923169267707086
320 95 15.398478173808572
320 100 22.864572914582915
340 0 0
340 5 0
340 10 0
340 15 0
340 20 0
340 25 0
340 30 0
340 35 0
340 40 0
340 45 0
340 50 0
340 55 0
340 60 0
340 65 0
340 70 0
340 75 0
340 80 0.8001600320064028
340 85 3.640728145629124
340 90 7.488986784140971
340 95 14.165666266506605
340 100 23.024604920984192
360 0 0
360 5 0
360 10 0
360 15 0
360 20 0
360 25 0
360 30 0
360 35 0
360 40 0
360 45 0
360 50 0
360 55 0
360 60 0
360 65 0
360 70 0
360 75 0
360 80 0.7204322593556078
360 85 3.3806761352270454
360 90 6.742697078831528
360 95 14.943910256410254
360 100 22.08883553421368
380 0 0
380 5 0
380 10 0
380 15 0
380 20 0
380 25 0
380 30 0
380 35 0
380 40 0
380 45 0
380 50 0
380 55 0
380 60 0
380 65 0
380 70 0
380 75 0
380 80 0.5404323458767069
380 85 3.5007001400280013
380 90 6.8254603682946335
380 95 14.522904580916185
380 100 22.246696035242287
400 0 0
400 5 0
400 10 0
400 15 0
400 20 0
400 25 0
400 30 0
400 35 0
400 40 0
400 45 0
400 50 0
400 55 0
400 60 0
400 65 0
400 70 0
400 75 0
400 80 0.48067294211896483
400 85 3.3633633633633586
400 90 6.242496998799519
400 95 14.068441064638781
400 100 23.324664932986593
420 0 0
420 5 0
420 10 0
420 15 0
420 20 0
420 25 0
420 30 0
420 35 0
420 40 0
420 45 0
420 50 0
420 55 0
420 60 0
420 65 0
420 70 0
420 75 0
420 80 0.4003202562049668
420 85 3.141256502601042
420 90 6.761352270454091
420 95 13.568140884530722
420 100 22.98919567827131
440 0 0
440 5 0
440 10 0
440 15 0
440 20 0
440 25 0
440 30 0
440 35 0
440 40 0
440 45 0
440 50 0
440 55 0
440 60 0
440 65 0
440 70 0
440 75 0
440 80 0.200080032012806
440 85 3.0218130878527094
440 90 6.4051240992794245
440 95 13.4453781512605
440 100 21.024204840968196
460 0 0
460 5 0
460 10 0
460 15 0
460 20 0
460 25 0
460 30 0
460 35 0
460 40 0
460 45 0
460 50 0
460 55 0
460 60 0
460 65 0
460 70 0
460 75 0
460 80 0.4601840736294549
460 85 2.7005401080216096
460 90 6.841368273654735
460 95 12.70508203281312
460 100 20.92837134853942
480 0 0
480 5 0
480 10 0
480 15 0
480 20 0
480 25 0
480 30 0
480 35 0
480 40 0
480 45 0
480 50 0
480 55 0
480 60 0
480 65 0
480 70 0
480 75 0
480 80 0.3800760152030458
480 85 3.0224179343474766
480 90 5.542216886754703
480 95 13.522704540908181
480 100 21.87750200160128
500 0 0
500 5 0
500 10 0
500 15 0
500 20 0
500 25 0
500 30 0
500 35 0
500 40 0
500 45 0
500 50 0
500 55 0
500 60 0
500 65 0
500 70 0
500 75 0
500 80 0.46027616569942476
500 85 2.901741044626771
500 90 6.162464985994398
500 95 13.265306122448983
500 100 19.603524229074885
EOD
set contour base
set cntrparam level incremental 0, 10, 100
unset surface
set table 'cont.dat'
splot '$complete'
unset table
plot [0:100][0:150] '$complete' using 2:1:3 with image , 'cont.dat' w l lt -1 lw 1.5
and the figure is
which has the isolines rotated. I would like to ask how to rotate the isolines.
Besides, I would like to ask how I could make a plot of the data with colors not blurred like this
to compare which of the two represents better the data block.
Regards

If you do not specify using ... gnuplot will plot using 1:2, but in your case you need 2:1, that's why x and y are switched (rotated).
If you add/change the following lines:
set palette maxcolors 10
plot [0:100][0:150] '$complete' using 2:1:3 with image , 'cont.dat' u 2:1 w l lt -1 lw 1.5
You should get something like this:

Related

Exporting a pandas DataFrame into excel based on cell values

I've a Dataframe as below. (resulted from pivot_table() method)
Location Loc 2 Loc 3 Loc 5 Loc 8 Loc 9
Item
1 404 317 272 113 449
3 1,205 870 846 371 1,632
5 208 218 128 31 268
7 107 54 57 17 179
9 387 564 245 83 571
10 364 280 115 34 252
16 104 80 72 22 143
17 111 85 44 10 209
18 124 182 67 27 256
19 380 465 219 103 596
if you take a closer look at it, there are missing Locations (eg, Loc 1, Loc, 4, etc) and missing Items (eg, 2, 4,8, etc)
I want to export this to my Excel pre-defined Template which has all the Locations & Items & fill the table based on Items & Values.
I know I can export the dataframe to a different excel sheet & use SUMIFS() or INDEX(), MATCH() formulas. but, I want to do this directly from Python/Panda to excel.
Below should be the result after exporting
Loc 1 Loc 2 Loc 3 Loc 4 Loc 5 Loc 6 Loc 7 Loc 8 Loc 9
1 0 404 317 0 272 0 0 113 449
2 0 0 0 0 0 0 0 0 0
3 0 1205 870 0 846 0 0 371 1632
4 0 0 0 0 0 0 0 0 0
5 0 208 218 0 128 0 0 31 268
6 0 0 0 0 0 0 0 0 0
7 0 107 54 0 57 0 0 17 179
8 0 0 0 0 0 0 0 0 0
9 0 387 564 0 245 0 0 83 571
10 0 364 280 0 115 0 0 34 252
11 0 0 0 0 0 0 0 0 0
12 0 0 0 0 0 0 0 0 0
13 0 0 0 0 0 0 0 0 0
14 0 0 0 0 0 0 0 0 0
15 0 0 0 0 0 0 0 0 0
16 0 104 80 0 72 0 0 22 143
17 0 111 85 0 44 0 0 10 209
18 0 124 182 0 67 0 0 27 256
19 0 380 465 0 219 0 0 103 596
20 0 0 0 0 0 0 0 0 0
Use DataFrame.reindex with new index and columns values in arrays or lists:
idx = np.arange(1, 21)
cols = [f'Loc {x}' for x in np.arange(1, 10)]
df = df.reindex(index=idx, columns=cols, fill_value=0)
print (df)
Loc 1 Loc 2 Loc 3 Loc 4 Loc 5 Loc 6 Loc 7 Loc 8 Loc 9
1 0 404 317 0 272 0 0 113 449
2 0 0 0 0 0 0 0 0 0
3 0 1,205 870 0 846 0 0 371 1,632
4 0 0 0 0 0 0 0 0 0
5 0 208 218 0 128 0 0 31 268
6 0 0 0 0 0 0 0 0 0
7 0 107 54 0 57 0 0 17 179
8 0 0 0 0 0 0 0 0 0
9 0 387 564 0 245 0 0 83 571
10 0 364 280 0 115 0 0 34 252
11 0 0 0 0 0 0 0 0 0
12 0 0 0 0 0 0 0 0 0
13 0 0 0 0 0 0 0 0 0
14 0 0 0 0 0 0 0 0 0
15 0 0 0 0 0 0 0 0 0
16 0 104 80 0 72 0 0 22 143
17 0 111 85 0 44 0 0 10 209
18 0 124 182 0 67 0 0 27 256
19 0 380 465 0 219 0 0 103 596
20 0 0 0 0 0 0 0 0 0

Convert Glyph path to SVG

I have the following glyph path:
<glyph glyph-name="right-nav-workflow" unicode="" d="M251 101c0 65 0 131 0 196 26 0 52 0 78 0 0 27 0 54 0 81-29 7-52 23-67 50-11 20-14 41-10 64 8 45 48 79 92 81 49 1 88-29 102-79 2 0 4 0 6 0 20 0 40 0 60 0 5 0 8 1 11 5 32 32 64 64 96 96 2 1 3 3 4 4 42-42 84-84 127-127-1 0-2-2-4-4-32-32-65-65-98-98-2-2-4-6-4-10 0-21 0-43 0-64 30-8 53-24 67-52 12-21 15-44 9-68-11-46-55-78-102-75-48 3-88 42-92 91-4 48 28 91 78 104 0 1 1 3 1 4 0 21 0 42 0 62 0 3-2 5-3 7-28 28-55 55-83 83-1 1-3 3-5 3-22 0-45 0-68 0-5-19-13-36-27-50-14-14-31-23-50-27 0-27 0-53 0-81 26 0 52 0 78 0 0-65 0-130 0-196-65 0-131 0-196 0z m157 156c-40 0-79 0-118 0 0-39 0-78 0-117 40 0 79 0 118 0 0 39 0 78 0 117z m275-58c0 33-26 59-59 59-32 0-59-26-59-59 0-33 27-59 60-59 32 0 58 26 58 59z m-334 216c33 0 59 27 59 59 0 33-26 59-59 59-33 0-59-26-59-59 0-33 26-59 59-59z m275-11c23 23 46 46 69 69-23 23-47 46-69 68-23-22-46-46-69-69 23-22 46-45 69-68z" horiz-adv-x="1000" />
How can I convert this into SVG? I tried to save it in a text file with svg extension but seems is not working.
Take the raw drawing data, put it in a path element, remove the glyph specific attributes, add an appropriate viewBox. Now you have something that works as an inline SVG. If you want to save it as a standalone SVG, then you need to add a name space declaration.
<svg height="400px" width="400px" viewBox="0 0 1000 1000">
<path transform="scale(1,-1) translate(0,-650)" fill="none" stroke="red" stroke-width="1" d="M251 101c0 65 0 131 0 196 26 0 52 0 78 0 0 27 0 54 0 81-29 7-52 23-67 50-11 20-14 41-10 64 8 45 48 79 92 81 49 1 88-29 102-79 2 0 4 0 6 0 20 0 40 0 60 0 5 0 8 1 11 5 32 32 64 64 96 96 2 1 3 3 4 4 42-42 84-84 127-127-1 0-2-2-4-4-32-32-65-65-98-98-2-2-4-6-4-10 0-21 0-43 0-64 30-8 53-24 67-52 12-21 15-44 9-68-11-46-55-78-102-75-48 3-88 42-92 91-4 48 28 91 78 104 0 1 1 3 1 4 0 21 0 42 0 62 0 3-2 5-3 7-28 28-55 55-83 83-1 1-3 3-5 3-22 0-45 0-68 0-5-19-13-36-27-50-14-14-31-23-50-27 0-27 0-53 0-81 26 0 52 0 78 0 0-65 0-130 0-196-65 0-131 0-196 0z m157 156c-40 0-79 0-118 0 0-39 0-78 0-117 40 0 79 0 118 0 0 39 0 78 0 117z m275-58c0 33-26 59-59 59-32 0-59-26-59-59 0-33 27-59 60-59 32 0 58 26 58 59z m-334 216c33 0 59 27 59 59 0 33-26 59-59 59-33 0-59-26-59-59 0-33 26-59 59-59z m275-11c23 23 46 46 69 69-23 23-47 46-69 68-23-22-46-46-69-69 23-22 46-45 69-68z"/>
</svg>
Update - Robert points out that the SVG Fonts spec has a y axis (0 on the bottom) that's inverted from the SVG norm (0 is the top) -> so you also need to flip the drawing along the x axis by using a scale (1,-1).

Incorrect logical indexing?

For the code:
dataset = pd.read_csv("/Users/Akshita/Desktop/EE660/donor_raw_data_medmean.csv", header=None, names=None)
# Separate data and label
X_label = dataset[1:19373][0]
X_data = dataset[1:19373]
print(X_data[X_label==1])
I get the output:(There are actually 4000~ samples with label=1)
0 1 2 3 4 5 6 7 8 9 ... 51 52 53 54 55 56 57 58 \
16386 1 17 60 0 1 0 0 0 0 1 ... 0 20 20 20 5 10 15 15
16396 1 137 60 0 1 0 0 0 0 1 ... 15 25 10 15 6 14 16 120
16399 1 89 54 0 1 0 0 0 0 1 ... 10 15 5 15 6 14 16 79
16402 1 89 75 0 1 0 0 0 0 1 ... 25 35 10 35 6 13 15 79
..
..
19356 1 101 80 1 0 0 1 0 0 2 ... 25 30 5 28 7 16 18 101
19363 1 65 70 1 0 0 1 0 0 1 ... 7 12 5 10 4 8 20 63
19372 1 29 70 0 0 0 1 0 0 2 ... 0 25 25 25 4 9 24 24
..
[859 rows x 61 columns]
and for
print(X_data[X_label==0])
I get the output:(There are about 15000~ samples with label=0)
0 1 2 3 4 5 6 7 8 9 ... 51 52 53 54 55 56 57 58 \
16384 0 17 74 0 1 0 0 0 0 1 ... 0 15 15 15 4 10 17 17
16385 0 17 60 0 1 0 0 0 0 2 ... 0 15 15 15 4 11 17 17
16387 0 29 67 0 1 0 0 0 0 1 ... 0 20 20 20 5 11 23 28
16388 0 53 60 0 1 0 0 0 0 1 ... 5 30 25 30 5 11 26 52
16389 0 65 49 0 1 0 0 0 0 1 ... 30 35 5 27 6 13 16 56
..
..
19369 0 137 77 1 0 1 0 0 0 1 ... 9 10 1 10 6 13 21 130
19370 0 29 60 1 0 0 1 0 0 1 ... 0 15 15 15 3 9 23 23
19371 0 129 78 1 0 0 1 0 0 2 ... 20 25 5 25 7 24 8 129
What can I be doing wrong?

Benchmarking CPU and File IO for an application running on Linux

I wrote two programs to run on Linux, each using a different algorithm, and I want to find a way (preferably using a benchmarking software) to compare the CPU usage and IO operations between these two programs.
Is there such a thing? and if yes, where can I find them. Thanks.
You can try hardinfo
Or there are like n different tools measuring system performance if measuring it while running your app solves your purpose
And you can also check this thread
You might try vmstat command:
vmstat 2 20 > vmstat.txt
20 samples of 2 seconds
bi = KB in, bo = KB out with wa = waiting for I/O
I/O can also increase cache demands
%CPU utilisation = us (user) = sy (system)
procs -----------memory---------- ---swap-- -----io---- -system-- ----cpu----
r b swpd free buff cache si so bi bo in cs us sy id wa
0 0 0 277504 17060 82732 0 0 91 87 1432 236 11 3 84 1
0 0 0 277372 17068 82732 0 0 0 24 1361 399 23 8 59 10
test start
0 1 0 275240 17068 82732 0 0 0 512 1342 305 24 4 69 4
2 1 0 275232 17068 82780 0 0 24 10752 4176 216 7 8 0 85
1 1 0 275240 17076 82732 0 0 12288 2590 5295 243 15 8 0 77
0 1 0 275240 17076 82748 0 0 8 11264 4329 214 6 12 0 82
0 1 0 275240 17076 82780 0 0 16 11264 4278 233 15 10 0 75
0 1 0 275240 17084 82780 0 0 19456 542 6563 255 10 7 0 83
0 1 0 275108 17084 82748 0 0 5128 3072 3501 265 16 37 0 47
3 1 0 275108 17084 82748 0 0 924 5120 8369 3845 12 33 0 55
0 1 0 275116 17092 82748 0 0 1576 85 11483 6645 5 50 0 45
1 1 0 275116 17092 82748 0 0 0 136 2304 689 3 9 0 88
2 1 0 275084 17100 82732 0 0 0 352 2374 800 14 26 0 61
0 0 0 275076 17100 82732 0 0 546 118 2408 1014 35 17 47 1
0 1 0 275076 17104 82732 0 0 0 62 1324 76 3 2 89 7
1 1 0 275076 17108 82732 0 0 0 452 1879 442 8 13 66 12
0 0 0 275116 17108 82732 0 0 800 352 2456 1195 19 17 56 8
0 1 0 275116 17112 82732 0 0 0 54 1325 76 4 1 88 8
test end
1 1 0 275116 17116 82732 0 0 0 510 1717 286 6 10 72 11
1 0 0 275076 17116 82732 0 0 1600 1152 3087 1344 23 29 41 7

Convert a vector in R to a dataframe by columns

I would like to convert this vector with strings in each row and spaces separating the elements within one string:
> v.input_red
[1] "pm 0 100 2.1 59 70 15.5 14.8 31 984 32 0 56 55 0 0 0 0 0 0 -60 -260 0 0 6 0 0 0 0 0 20 8 2ff 0 249 0 0 "
[2] "pm 0 100 2.1 59 70 15.5 14.8 31 984 32 0 56 55 0 0 0 0 0 0 -60 -260 0 0 6 0 0 0 0 0 20 8 2ff 0 249 0 0 "
[3] "pm 0 100 2.1 59 70 15.5 14.8 31 984 32 0 56 55 0 0 0 0 0 0 -60 -260 0 0 6 0 0 0 0 0 20 8 2ff 0 249 0 0 "
to a dataframe with a column for each element. But I'm not quite sure how to extract the elements from the strings. Best way would be to convert the whole thing at once somehow, I guess..
Wanted result-dataframe (created manually):
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17 V18 V19 V20 V21 V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33 V34 V35
1 pm 0 100 2.1 59 70 15.5 14.8 31 984 32 0 56 55 0 0 0 0 0 0 -60 -260 0 0 6 0 0 0 0 0 20 8 2ff 0 249
2 pm 0 100 2.1 59 70 15.5 14.8 31 984 32 0 56 55 0 0 0 0 0 0 -60 -260 0 0 6 0 0 0 0 0 20 8 2ff 0 249
3 pm 0 100 2.1 59 70 15.5 14.8 31 984 32 0 56 55 0 0 0 0 0 0 -60 -260 0 0 6 0 0 0 0 0 20 8 2ff 0 249
Thanks in advance!
Matthias
For quite some time, read.table and family have had a text argument that lets you read directly from character vectors. There's no need to write the object to a file first.
Your sample data...
v.input_red <- c("pm 0 100 2.1 59 70 15.5 14.8 31 984 32 0 56 55 0 0 0 0 0 0 -60 -260 0 0 6 0 0 0 0 0 20 8 2ff 0 249 0 0 ",
"pm 0 100 2.1 59 70 15.5 14.8 31 984 32 0 56 55 0 0 0 0 0 0 -60 -260 0 0 6 0 0 0 0 0 20 8 2ff 0 249 0 0 ",
"pm 0 100 2.1 59 70 15.5 14.8 31 984 32 0 56 55 0 0 0 0 0 0 -60 -260 0 0 6 0 0 0 0 0 20 8 2ff 0 249 0 0 ")
... directly read in:
read.table(text = v.input_red, header = FALSE)
# V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15 V16 V17
# 1 pm 0 100 2.1 59 70 15.5 14.8 31 984 32 0 56 55 0 0 0
# 2 pm 0 100 2.1 59 70 15.5 14.8 31 984 32 0 56 55 0 0 0
# 3 pm 0 100 2.1 59 70 15.5 14.8 31 984 32 0 56 55 0 0 0
# V18 V19 V20 V21 V22 V23 V24 V25 V26 V27 V28 V29 V30 V31 V32 V33
# 1 0 0 0 -60 -260 0 0 6 0 0 0 0 0 20 8 2ff
# 2 0 0 0 -60 -260 0 0 6 0 0 0 0 0 20 8 2ff
# 3 0 0 0 -60 -260 0 0 6 0 0 0 0 0 20 8 2ff
# V34 V35 V36 V37
# 1 0 249 0 0
# 2 0 249 0 0
# 3 0 249 0 0
Assuming file is a file name that you save on your system:
writeLines(v.input_red, file)
data <- read.table(file)
Is this solution what you were looking for?
s1 <- "pm 0 100 2.1 59 70 15.5 14.8 31 984 32 0 56 55 0 0 0 0 0 0 -60 -260 0 0 6 0 0 0 0 0 20 8 2ff 0 249 0 0 "
s2 <- "pm 0 100 2.1 59 70 15.5 14.8 31 984 32 0 56 55 0 0 0 0 0 0 -60 -260 0 0 6 0 0 0 0 0 20 8 2ff 0 249 0 0 "
s3 <- "pm 0 100 2.1 59 70 15.5 14.8 31 984 32 0 56 55 0 0 0 0 0 0 -60 -260 0 0 6 0 0 0 0 0 20 8 2ff 0 249 0 0 "
df <- t(data.frame(strsplit(s1, " "),strsplit(s2, " "),strsplit(s3, " ")))
row.names(df) <- c("s1", "s2", "s3")
strsplit splits the string at each space char. Concatenated as data.frame gives you a df wih 3 columns. So you have to transpose it with t. I changes row names for better readability.

Resources