• R/O
  • SSH

提交

标签
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#objective-cqtwindows誰得cocoapythonphprubygameguibathyscaphec翻訳omegat計画中(planning stage)frameworktwittertestdomvb.netdirectxbtronarduinopreviewerゲームエンジン

Commit MetaInfo

修订版ea6948d69378820ff97ee3e52f62e6adc3fd0b63 (tree)
时间2022-09-28 15:56:57
作者Lorenzo Isella <lorenzo.isella@gmai...>
CommiterLorenzo Isella

Log Message

A simple script to generate a JSON file.

更改概述

差异

diff -r a27f97f7f503 -r ea6948d69378 R-codes/convert_to_json.R
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/R-codes/convert_to_json.R Wed Sep 28 08:56:57 2022 +0200
@@ -0,0 +1,36 @@
1+library(tidyverse)
2+library(jsonlite)
3+
4+#See https://stackoverflow.com/questions/73859986/r-parsing-modifying-and-saving-a-json-file
5+
6+entry_1 <- tibble(x=c("AT", "IT", "HU"), value=c(12, 0.9, 4)) |>
7+ pivot_wider(names_from= x, values_from=value)
8+
9+
10+entry_2 <- tibble(x=c("FR", "IE", "RO"), value=c(1.2, 0.9, 4.8))|>
11+ pivot_wider(names_from= x, values_from=value)
12+
13+entry_3 <- tibble(x=c("DE", "FI", "EL"), value=c(1.7, 0.09, 4.7))|>
14+ pivot_wider(names_from= x, values_from=value)
15+
16+entry_4 <- tibble(x=c("SK", "LT", "BG"), value=c(1.8, 0.967, 4.6))|>
17+ pivot_wider(names_from= x, values_from=value)
18+
19+entry_5 <- tibble(x=c("FR", "IT", "IE"), value=c(129, 9.4, 4.3))|>
20+ pivot_wider(names_from= x, values_from=value)
21+
22+
23+
24+newdata <- list(entry_1, entry_2, entry_3, entry_4, entry_5)
25+names(newdata) <- c("entry_1", "entry_2", "entry_3", "entry_4", "entry_5")
26+
27+
28+## convert to Json and remove square brackets
29+
30+## see https://stackoverflow.com/a/7195889
31+
32+newdataJSON<-toJSON(newdata, pretty=TRUE, auto_unbox = TRUE) |>
33+ (\(x) gsub("\\[|\\]", "", x))()
34+
35+newdataJSON
36+