0

After R to JSON conversion, this should be the output:

{
    "alpha": [100,120,140,150,160],
    "beta": [0.6, 1, 1.5, 2],
    "gamma": [
        [
            0.018429082998491217,
            -0.1973461380810494,
            0.6373366343601572,
            0.1533790888325718,
            0.014712015654254968
        ],
        [
            0.012075950866910893,
            -0.14585424179257,
            0.6591589092698342,
            0.2571689477155383,
            0.010925520086793088
        ],
        [
            0.0159193430322232,
            -0.146917626129837,
            0.4710901890006199,
            0.15728143658310957,
            0.012566273548505473
        ],
        [
            0.017317835334994967,
            -0.1549043092753231,
            0.4882454969264185,
            0.1300951912298256,
            0.013437976685378085
        ]
    ]
}

This describes a matrix: alpha and beta are arrays which index the matrix depicted below by columns.

rjson::toJSON() function from rjson takes vector or list. However, it doesn't split an R matrix (with named rows and columns) in arrays; instead, it generates an array of row values and then names each column by its column name.

I cannot really figure out which R data structure allows producing such a file format.

Could you show me the R code that uses rjson::toJSON() function and generates that output?

Lisa Ann
  • 3,345
  • 6
  • 31
  • 42

0 Answers0