I used jsonlite
library: json_pca_data <- toJSON(pca_table, pretty = TRUE))
to produce JSON
:
{
"neuron_type" : [
"Ciliated_sensory_neurons",
"Touch_receptor_neurons",
...
...
],
"PC1" : [
4.1158,
-1.1647,
...
...
],
"PC2" : [
-1.4615,
1.9541,
...
...
],
"octr-1" : [
2.5517,
2.8857,
...
...
from the pca_table
that looks like that:
neuron_type PC1 PC2 octr-1
Ciliated_sensory_neurons 4.1157653 -1.4614620 2.551738
Touch_receptor_neurons -1.1647174 1.9540974 2.885656
...
...
But I want to add to the final JSON
also PC1: 0.36
and PC2: 0.21
. I can just modify the initial pca_table
:
pca_table$PC1_percent = percent[1]
pca_table$PC2_percent = percent[2]
Adding two columns and then transforming it into JSON
, however, I do not like to have
"PC1_percent" : [
0.3676,
0.3676,
0.3676,
0.3676,
0.3676,
0.3676,
0.3676,
0.3676,
0.3676
],
"PC2_percent" : [
0.2331,
0.2331,
0.2331,
0.2331,
0.2331,
0.2331,
0.2331,
0.2331,
0.2331
]
I want to have just key and value instead:
"PC1_percent" : 0.3676, "PC2_percent" : 0.2331
Is there a way to do that in Rstudio
?