Home > front end >  Putting results into a new dataframe
Putting results into a new dataframe

Time:08-20

Im looking to clean up my data so its more presentable. Is there anyway I can put the following data into a new df that contains 4 columns with the header of each being 'data' 'predicted' 'krige.var' ' error'

df
$data
 [1] 15.4 20.0 18.5  8.2 19.9 17.1 22.1 17.4 18.6 15.0 17.3 16.1 20.3 18.6 12.4 20.8 19.2 19.6 13.8 19.3

$predicted
 [1] 14.63828 19.99015 19.55968 17.31891 19.58819 17.12238 20.12373 17.54724 18.31672 15.16020 17.13020 13.54384 19.67269 17.6722 [15] 13.19682 19.62094 18.23890 19.02463 11.40030 19.65951

$krige.var
 [1] 5.564853 5.005181 6.331402 4.690094 5.533664 4.766348 5.239515 4.939733 4.981795 4.907894 4.675788 5.279128 5.432717 4.95924 [15] 7.305362 4.994287 4.736674 4.786049 6.854661 4.876816

$error
 [1]  0.761718919  0.009853859 -1.059682833 -9.118905118  0.311806163 -0.022383898 1.976266345 -0.147244475  0.283278859 -0.160198526  0.169802131  2.556161906  0.627305499  0.927774475 -0.796824408  1.179064489 0.961096163  0.575366428  2.399697891 -0.359506555

CodePudding user response:

If your data is just

df <- list(data = c(15.4, 20, 18.5, 8.2, 19.9, 17.1, 22.1, 17.4, 18.6, 15, 17.3, 16.1, 20.3, 18.6, 12.4, 20.8, 19.2, 19.6, 13.8, 19.3), predicted = c(14.63828, 19.99015, 19.55968, 17.31891, 19.58819, 17.12238, 20.12373, 17.54724, 18.31672, 15.1602, 17.1302, 13.54384, 19.67269, 17.6722, 13.19682, 19.62094, 18.2389, 19.02463, 11.4003, 19.65951), krige.var = c(5.564853, 5.005181, 6.331402, 4.690094, 5.533664, 4.766348, 5.239515, 4.939733, 4.981795, 4.907894, 4.675788, 5.279128, 5.432717, 4.95924, 7.305362,  4.994287, 4.736674, 4.786049, 6.854661, 4.876816), error = c(0.761718919, 0.009853859, -1.059682833, -9.118905118, 0.311806163, -0.022383898, 1.976266345, -0.147244475, 0.283278859, -0.160198526, 0.169802131, 2.556161906, 0.627305499, 0.927774475, -0.796824408, 1.179064489, 0.961096163, 0.575366428, 2.399697891, -0.359506555))

the just wrap in as.data.frame:

as.data.frame(df)
#    data predicted krige.var        error
# 1  15.4  14.63828  5.564853  0.761718919
# 2  20.0  19.99015  5.005181  0.009853859
# 3  18.5  19.55968  6.331402 -1.059682833
# 4   8.2  17.31891  4.690094 -9.118905118
# 5  19.9  19.58819  5.533664  0.311806163
# 6  17.1  17.12238  4.766348 -0.022383898
# 7  22.1  20.12373  5.239515  1.976266345
# 8  17.4  17.54724  4.939733 -0.147244475
# 9  18.6  18.31672  4.981795  0.283278859
# 10 15.0  15.16020  4.907894 -0.160198526
# 11 17.3  17.13020  4.675788  0.169802131
# 12 16.1  13.54384  5.279128  2.556161906
# 13 20.3  19.67269  5.432717  0.627305499
# 14 18.6  17.67220  4.959240  0.927774475
# 15 12.4  13.19682  7.305362 -0.796824408
# 16 20.8  19.62094  4.994287  1.179064489
# 17 19.2  18.23890  4.736674  0.961096163
# 18 19.6  19.02463  4.786049  0.575366428
# 19 13.8  11.40030  6.854661  2.399697891
# 20 19.3  19.65951  4.876816 -0.359506555
  • Related