Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all 207118 articles
Browse latest View live

GoogleVis chart not rendering in Rmarkdown

$
0
0

Outside of Rmarkdown the stand alone googleVis chart works fine, but when I plug it in the Rmarkdown file I am receiving just the Rmarkdown Code:

Viewer Output:

enter image description here

> TEST H 4/13/2016 require(googleVis) Loading required package:> googleVis Welcome to googleVis version 0.5.10 Please read the Google> API Terms of Use before you start using the package:> https://developers.google.com/terms/> > Note, the plot method of googleVis will by default use the standard> browser to display its output.   See the googleVis package vignettes> for more details, or visit http://github.com/mages/googleVis.   To> suppress this message use:> suppressPackageStartupMessages(library(googleVis))> > dttm = data.frame(DT_ENTRY=Sys.Date()-1:20,variable="x",value=1:20)> g1=gvisAnnotationChart(dttm,datevar="DT_ENTRY",numvar="value",idvar="variable")> plot(g1) starting httpd help server ... done

Rmarkdown Code Below:

---title: "test"author: "H"date: "4/13/2016"output: html_documenthighlight: tangonumber_sections: yes---```{r}require(googleVis)dttm = data.frame(DT_ENTRY=Sys.Date()-1:20,variable="x",value=1:20)g1=gvisAnnotationChart(dttm,datevar="DT_ENTRY",numvar="value",idvar="variable")plot(g1)```

Modifying data after mice and converting data back to mids object

$
0
0

I am unable to reproduce the error in question and cannot attach my full data. Any help understanding the error received would be appreciated.

After imputation, I make several changes to the imputed datasets and would like to convert the transformed data to a mids object for modeling. However, I get the following error:

Error in `[<-.data.frame`(`*tmp*`, j, value = list(variable = c(0.9998,  :   replacement element 1 has 78 rows, need 86

Below is a toy example of steps I take:

library(mice)library(dplyr)df <- data.frame(  id = rep(1:3, 3),  a = sample(c(NA, 1, 0), size=9, replace = T),  b = sample(c(NA, 1:10), size=9, replace = T))# perform imputationimp <- mice(df)# get complete data + transformcomp <- complete(imp, action="long", include = T) %>%  filter(id %in% 1:2) %>%  rowwise() %>%  mutate(add = sum(a,b, na.rm = T)) %>%  dplyr::ungroup()# convert to mids object - error encountered hereto_mids <- as.mids(comp)

add_xy_position in rstatix doesn't work for two-way ANOVA | tukey_hsd() | Error in `group_by()`:

$
0
0

I'm trying to perform Two-Way ANOVA statistical tests on my data and use the add_xy_position() on the test result in order to later visualize the p-values using ggplot similarly to: https://www.datanovia.com/en/blog/how-to-add-p-values-to-ggplot-facets/

Here's my example:

library(rstatix)library(tidyr)#Create the DataID <- 1:40 #Different Individuals (i.e. Test Subjects)Time <- c(rep('d24h', 20), rep('d48h', 20)) #Time of Sampling (unpaired), Strings are intended here for later visualizationGroup <- c(rep('A', 5), rep('B', 5), rep('A', 5), rep('B', 5)) #GroupsVal <- runif(40) #Readoutdf <- data.frame(ID, Time, Group, Val)

It works when performing the test for one categorical variable:

test1 <- df %>% tukey_hsd(Val~Group) %>% add_xy_position()test1# A tibble: 1 x 13  term  group1 group2 null.value estimate conf.low conf.high p.adj p.adj.signif y.position groups        xmin  xmax<chr> <chr>  <chr>       <dbl>    <dbl>    <dbl>     <dbl> <dbl> <chr>             <dbl> <named list> <dbl> <dbl>1 Group A      B               0    0.106  -0.0755     0.288 0.244 ns                0.968 <chr [2]>        1     2

However, when trying to perform the same for two categoricals, the following occurs:

test2 <- df %>% tukey_hsd(Val~Group*Time) %>% add_xy_position()test2Error in `group_by()`:! Must group by variables found in `.data`.x Column `Group:Time` is not found.Run `rlang::last_trace()` to see where the error occurred.

I tried to find solutions to the problem here on stack overflow but this issue seems to be unique to my case. I expected to get y positions to the results of the tukeyHSD test.

How to integrate GPT-4 model hosted on Azure with a chattr package?

$
0
0

I am currently looking to integrate the OpenAI GPT-4 model into my application. Here are the details I have:

  • Endpoint:https://xxxxxxxxxxxxxxx.openai.azure.com/
  • Location/Region:yyyyyyyyyyyyyyyyyyyyyyyy
  • Key: *******************
  • Deployment Name:gpt-4o
  • Model Name:gpt-4o
  • Model Version:2024-05-13

I want to integrate it with chattr. Could someone guide me on how to authenticate and make API requests to this endpoint?

I tried:

library(chattr)chattr_use("gpt4",     path = "https://xxxxxxxxxxxxxxx.openai.azure.com/",  model = "gpt-4o")

I saved the API under the .Renviron file.

#testingchattr::chattr("1+1")
{{error}}Type:Message: Resource not found! {error}Type:Message: Resource not foundError in `abort()`:! `message` must be a character vector, not a <httr2_response> object.Run `rlang::last_trace()` to see where the error occurred.

Changing font in PDF produced by rmarkdown

$
0
0

I am producing reports using rmarkdown. When knitting a PDF

---title: "Untitled"output: pdf_document---

I would like to specify the font to be used in creating the PDF. The official documentation (see section "LaTeX Options) says I can do this. enter image description hereHowever, I've never used LaTeX and fail to understand how such selection can be made in YAML options at the top of the .Rmd document used by rmarkdown package.

Question: How do I change the font in the PDF produced by rmarkdown?

sessionInfo() R version 3.1.0 (2014-04-10) Platform: x86_64-w64-mingw32/x64 (64-bit)

locale:[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   [3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          [5] LC_TIME=English_United States.1252    attached base packages:[1] grid      stats     graphics  grDevices utils     datasets  methods   base     other attached packages:[1] ggplot2_1.0.0 RODBC_1.3-10  knitr_1.6     dplyr_0.2

I've never used LaTeX and don't want to get into it at this very mom

Returning a matrix after removing duplicate combinations of elements

$
0
0

I'm trying to obtain a matrix from which pairwise combinations of duplicates have been removed.

For example:

m <- cbind(c("A", "B"), c("B", "A"))

since BA is a duplicate from AB, I'm removing it from the matrix with

m[!duplicated(t(apply(m, 1, sort))), ]

which returns a vector with

"A" "B"

instead of a matrix with nrow of 1.

     [,1] [,2][1,] "A"  "B" 

If I use as.matrix(m), I'm getting

     [,1][1,] "A" [2,] "B" 

instead of

     [,1] [,2][1,] "A"  "B" 

This only happens with nrow = 1. In cases where more rows are returned, the result is kept as a matrix:

m <- cbind(c("A", "B", "A"), c("B", "A", "C"))m[!duplicated(t(apply(m, 1, sort))), ]

which gives

     [,1] [,2][1,] "A"  "B" [2,] "A"  "C"  

How can I obtain a matrix, where only one row is returned. And what's the reason that only a vector is returned and not a matrix in the example above?

Create dropdown list in R using plotly?

$
0
0

I want to create a dropdown list with the years 2019 to 2024 for this plot:

enter image description here

I'm using R Markdown and plotly to create the interactive plot. I managed to make this plot for 2021, but I can't seem to add the dropdown list to filter the plot by year.

The code I'm using:

dadosbr <- data.frame(  TIPO_DE_RESISTENCIA = sample(c("Primária", "Adquirida", "Ignorado"), 7525, replace = TRUE),  Regiao = sample(c("Centro-Oeste", "Nordeste", "Norte", "Sudeste", "Sul"), 7525, replace = TRUE),  ANO_TRAT = sample(2019:2024, 7525, replace = TRUE),  UF = sample(c("Acre", "Alagoas", "Amapá", "Amazonas", "Bahia", "Ceará", "Distrito Federal", "Espírito Santo", "Goiás", "Maranhão", "Mato Grosso", "Mato Grosso do Sul","Minas Gerais", "Pará", "Paraíba", "Paraná", "Pernambuco", "Piauí", "Rio de Janeiro", "Rio Grande do Norte", "Rio Grande do Sul", "Rondônia", "Roraima","Santa Catarina", "São Paulo", "Sergipe", "Tocantins"), 7525, replace = TRUE))graf9 <- dadosbr %>%  group_by(ANO_TRAT, Regiao, TIPO_DE_RESISTENCIA, UF) %>%  tally() %>%  mutate(TIPO_DE_RESISTENCIA = factor(TIPO_DE_RESISTENCIA, levels = c("Primária", "Adquirida", "Ignorado")))# Convert ggplot object to plotlygraf9_plotly <- ggplot(graf9, aes(x = UF, y= n, fill = TIPO_DE_RESISTENCIA)) +  geom_bar(position = "fill", stat = "identity") +  labs(x = "UF de residência",        y = "% casos TBDR",       fill = "Tipo de resistência")+  scale_fill_brewer(palette = "Set1", direction = 1) +  theme_classic() +  scale_y_continuous(labels = scales::percent, expand = expansion(mult = c(0, .1))) +  facet_grid(. ~ Regiao , scales = "free", space = "free") +  theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5)) +  theme(    legend.position = "right",    axis.line = element_line(colour = "black"),    axis.text.x = element_text(colour = "black"),    axis.text.y = element_text(colour = "black"),    plot.caption = element_text(hjust = 0.5, vjust = 1, margin = margin(t = 10), size = 10),    plot.title = element_text(hjust = 0.5, vjust = 1, margin = margin(t = 10), size = 12)  )# Convert ggplot to plotlygraf9_plotly <- ggplotly(graf9_plotly)# Display the plotly objectgraf9_plotly

I had the ggplot code and with some chatgpt help I got to make it into an interactive plot.

`pivot_longer` with`names_transform`

$
0
0

All examples I can find of pivot_longer using names_transform, have the following pattern:

df %>% pivot_longer(    ...    names_to = "x",     names_transform = list(x = some_func) # same name as names_to)

Is there another useful form of argument to names_transform, that justifies having to supply the argument as a named list?

NB: names_transform = list(x = f1, y=f2) has no effect on the column y in my tibble.


Support with recoding likert questions in R

$
0
0

I am new to R but i need to use it as i cannot access spss at this moment. So my issue is i am trying to recode my likert scale questions i already took out the array i want and renamed to "lik". I have also changed the column names to "life satisfaction Q1-Q4".

I am trying to recode the likert questions and have done thes

rmydata.reloaded1 <- lik %>%  mutate(across(c("Life Satisfaction Q1", "Life Satisfaction Q2", "Life Satisfaction Q3", "Life Satisfaction Q4"),                ~ recode(., "Disagree" = 1, "Neutral" = 2, "Agree" = 3, "Strongly agree" = 4)))

I recieved a error warning

Error in `mutate()`:ℹ In argument: `Life Satisfaction Q1 = recode(...)`.Caused by error in `recode()`:! unused arguments (Disagree = 1, Neutral = 2, Agree = 3, `Strongly agree` = 4)Run `rlang::last_trace()` to see where the error occurred.Warning message:`funs()` was deprecated in dplyr 0.8.0.

I also did this

mydata.reloaded1 <- lik %>% mutate_at(c("Life Satisfaction Q1", "Life Satisfaction Q2", "Life Satisfaction Q3", "Life Satisfaction Q4"), +                                       funs(recode(., "Disagree"=1, "Neutral"=2, "Agree"=3, "Strongly agree"=4)))

and recieved this

Error in `mutate()`:ℹ In argument: `Life Satisfaction Q1 = recode(...)`.Caused by error in `recode()`:! unused arguments (Disagree = 1, Neutral = 2, Agree = 3, `Strongly agree` = 4)Run `rlang::last_trace()` to see where the error occurred.Warning message:`funs()` was deprecated in dplyr 0.8.0.

Hence, i can not seem to figure what i keep doing wrong, any support would be appreciated.

Mannkendall test and Sens Slope Estimator in R

$
0
0

I have time series data for three different stations in different rows in a excel sheet. I want to calculate stationwise p-value, Tau, S using MannKendall test, and sens slope value usinf Senslope Estimator in R. I am new in R, so I am unable to calculate all these. I want to export my result in a single table, where each row will show each station and each coulmn will include all statistics from Mannkendall and Senslope.

Please find my data attached.

I am new in R, so I am unable to calculate all these. I want to export my result in a single table, where each row will show each station and each coulmn will include all statistics from Mannkendall and Senslope.

Please find my data below.

https://docs.google.com/spreadsheets/d/1I3xtbv7PZzpwAEaSVJdYnJmx48hV_pgw/edit?usp=sharing&ouid=109009523684189650869&rtpof=true&sd=true

merge multiple DFs based on column names and row names in R

$
0
0

I have 3 Dfs

I need to split it based on columns and row names like shown below

I tried merge_recurse option from reshape, looks like it merges row by row. Please help me to get the columns added side by side.

The final output should merge same columns from all DFs in to each new DFs like below,

  C1.DF1 C1.DF2 C1.DF3G1  0      1     NAG2  3      NA    1G3  3      NA    2G4  NA     0         NAG5  NA     2         NAG6  NA     NA    4    C2.DF1  C2.DF2  C2.DF3G1  0          2    NAG2  1         NA    1G3  1         NA    3G4  NA         2    NAG5  NA         1    NAG6  NA        NA    3  C3.DF1    C3.DF2  C3.DF3G1  1          3     NAG2  2          NA    1G3  1          NA    4G4  NA         2     NAG5  NA         3     NAG6  NA         NA    2
df1<- data.frame(C1=c(0,3,3),C2=c(0,1,1),C3=c(1,2,1),row.names = c("G1","G2","G3"))df2<- data.frame(C1=c(1,0,2),C2=c(2,2,1),C3=c(3,2,3),row.names = c("G1","G4","G5"))df3<- data.frame(C1=c(1,2,4),C2=c(1,3,3),C3=c(1,4,2),row.names = c("G2","G3","G6"))df_list<- list(df1,df2,df3)data<- merge_recurse(df_list)

This is what i got after using merge_recurse. (https://i.sstatic.net/wiwfS8eY.png)

Change text of full_screen button ("Expand") in bslib card

$
0
0

How can one change the text (I need basically the translation to another language) of the expand button (which is created by full_screen = TRUE) and the close button in the full screen?

enter image description hereenter image description here

MWE:

library(shiny)library(bslib)# Define UIui <- fluidPage(  theme = bs_theme(bootswatch = "minty"),  titlePanel("Table in a card()"),    mainPanel(      card(        title = "Data Table",        full_screen = TRUE,        tableOutput("mytable")      )  ))# Define server logicserver <- function(input, output) {  # Generate sample data  data <- data.frame(    Name = c("John", "Jane", "Alice", "Bob", "Charlie", "David"),    Age = c(25, 30, 35, 40, 45, 50),    Score = c(80, 75, 90, 85, 88, 92)  )  # Render table  output$mytable <- renderTable({    filtered_data <- data  })}# Run applicationshinyApp(ui = ui, server = server)

Adding a user selected folder directly accessible in shinyDirChoose

$
0
0

I want to add an accessible folder to a user-selected directory in shinyDirChoose by modifying roots. It seems it works to modify roots, but when I next select this directory in the volume, I get the error message "Error in: path must not have missing values".

library(shiny)library(shinyFiles)library(fs)ui <- fluidPage(  titlePanel("Add Volume to Roots in Shiny"),  shinyDirButton("dir1", "Select Directory 1", "Please select a directory"),  verbatimTextOutput("roots_info"))server <- function(input, output, session) {  # Initial roots definition  roots <- reactiveVal(c(    home = fs::path_home(),    output = paste0(fs::path_home(), "/Eclipse")  ))  # Show the current roots information  output$roots_info <- renderPrint({ roots() })  # Initialize shinyDirChoose for the directories  observe({ shinyDirChoose(input, "dir1", roots = roots()) })  # # Handle the directory selection   observeEvent(input$dir1, {     dir1 <- parseDirPath(roots(), input$dir1)     if (!is.null(dir1) && !anyNA(dir1) && length(dir1) > 0) {       new_roots <- roots()       new_roots["custom"] <- dir1       roots(new_roots)         }   })}shinyApp(ui, server)

How to retrieve Common Table Expressions (CTEs) as a R list?

$
0
0

Context

I am connected to a PostgreSQL database and I use dplyr+dbplyr to query it. One of the query is quite long and complex and uses multiple CTEs.

Problem

I need to use these CTEs to make some plots and analysis within R but I do not know how to get them as "separated" dataframes within R.

I tried to break down the long query into smaller ones but this obviously fails when one CTE needs a previous one.

Question

How to retrieve the CTEs of a query as a list of dataframes in R?

Example

Please find below a small example illustrating the question. The query is very dumb but I feel it is enough for illustration purpose.

# Packages ----if(!require("dbplyr")){install.packages("dbplyr")}; library(dbplyr)if(!require("tidyverse")){install.packages("tidyverse")}; library(tidyverse)# Set up the example database using the iris dataset ----con <- DBI::dbConnect(RSQLite::SQLite(), ":memory:")copy_to(con, iris)# Query using the "WITH" command ----query = sql("WITH  tbl_set AS (SELECT * FROM iris WHERE Species = 'setosa'),  tbl_ver AS (SELECT * FROM iris WHERE Species = 'versicolor'),  tbl_all AS (    SELECT *    FROM tbl_set     UNION ALL SELECT * FROM tbl_ver)SELECT * FROM tbl_all")

Expected output

The expected output is an object in the R environment, for example a list containing each CTE as dataframes, see below the expected structure:

# Target output ----list(  tbl_set = filter(iris, Species == "setosa"),  tbl_ver = filter(iris, Species == "versicolor"),  tbl_all = collect(tbl(con, query)))#> $tbl_set#>    Sepal.Length Sepal.Width Petal.Length Petal.Width Species#> 1           5.1         3.5          1.4         0.2  setosa#> 2           4.9         3.0          1.4         0.2  setosa#> 3           4.7         3.2          1.3         0.2  setosa#> 4           4.6         3.1          1.5         0.2  setosa#> #> $tbl_ver#>    Sepal.Length Sepal.Width Petal.Length Petal.Width    Species#> 1           7.0         3.2          4.7         1.4 versicolor#> 2           6.4         3.2          4.5         1.5 versicolor#> 3           6.9         3.1          4.9         1.5 versicolor#> 4           5.5         2.3          4.0         1.3 versicolor#> #> $tbl_all#> # A tibble: 100 × 5#>    Sepal.Length Sepal.Width Petal.Length Petal.Width Species#>           <dbl>       <dbl>        <dbl>       <dbl> <chr>  #>  1          5.1         3.5          1.4         0.2 setosa #>  2          4.9         3            1.4         0.2 setosa #>  3          4.7         3.2          1.3         0.2 setosa #>  4          4.6         3.1          1.5         0.2 setosa #> # ℹ 90 more rows

Created on 2024-07-04 with reprex v2.1.0

Add a link to a table in rmarkdown document

$
0
0

I want to add a link to a word with a table within the same rmarkdown document. Here is what I tried, but this did not work.

---title: 'test'output:  pdf_document:    latex_engine: pdflatex---

--- {r glob_opt, echo = FALSE} knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE )---

Dummy text
Lorem ipsum dolor sit amet, see [sample data](#tab:iris) consectetur adipiscing elit. Suspendisse neque risus, interdum ac nunc non, tempus sollicitudin sapien.

Afrer, see I would like to add a link to the table on the sample data.

---{r packages} library(ggplot2) library(dplyr) library(gt)---

---{r tab.cap= 'iris'} head(iris, 3) %>% gt() %>% tab_header(title = "Table 1: sample data"))---


geom_ribbon does not follow the order of my vector (ggplot)

$
0
0

I am trying to plot a pressure distribution from an airfoil with some confidence bounds at each point. Hence, I was trying to implement the geom_ribbon function to create continuous shaded bounds. A simple example should go like this:

x = c(1, .8, .6, .4, .2, 0, .1,.3,.5,.7,.9)y = c(-10,-10,-15,-20,-100,-400,10000,6000,800,300,80)ymax = y*1.1ymin = y*.9df = data.frame(x,y)mdf = melt(df, id.vars="x")ggplot() +geom_path(data=mdf, aes(x=x, y=value)) +geom_ribbon(aes(x, ymin=ymin,ymax=ymax))

The problem is that the geom_ribbon function does not follow the original order of my vector when plotting, but it re-orders everything in ascending manner such as geom_line does. I would like to use geom_ribbon in the same manner as geom_path, but I cannot find a command to make it work in such way.

Can I force a ggplot to an A4 word page without changing fig.height, fig.width and dpi parameters?

$
0
0

Given the same ggplot with two different fig.height/fig.width chunk header configurations one can see that the outputs look different. The points in Plot 2 are more conjested and the fonts are bigger. For Plot 1 the opposite is the case.

I'm looking for a programmatic solution to produce Plot 1 and keep it in the given A4 boundaries (theoretically I can manually reduce the size when the word doc is open). I'm showing Plot 2 to clarify that adjusting fig.height/fig.width will not prduce the desired output. Also dpi must be 600.

---output:  officedown::rdocx_document:    base_format: "rmarkdown::word_document"---# Plot 1```{r, fig.height = 10, fig.width = 10, echo = FALSE, message = FALSE, dpi = 600}library(officedown) # 0.3.0library(ggplot2) # 3.4.2df <- data.frame(A = sample(1000), B = sample(1000), size = sample(1000))ggp <- ggplot(data = df, aes(x = A, y = B, size = size)) +  geom_point()ggp```# Plot 2```{r, fig.height = 7, fig.width = 7, echo = FALSE, message = FALSE, dpi = 600}ggp```

Numbered tables using `gt` package in Rmarkdown with pdf output

$
0
0

When rendering a Rmarkdown file to pdf using the bookdown::pdf_document2 output, how can I obtain a table with a numbered caption (e.g. Table 1: caption) when rendering a table with the gt package ?It works if I render the table using knitr, but not with gt.

I also saw the following advice in the bookdown documentation:

If you decide to use other R packages to generate tables, you have to make sure the label for the table environment appears in the beginning of the table caption in the form (\#label) (again, label must have the prefix tab:)

However, this does not work for me either.

Here is a MWE of a Rmarkdown file that reproduces the problem:

---output: bookdown::pdf_document2---```{r, echo = FALSE}gt::gt(head(iris)) |>  gt::tab_header("Iris data set using `gt`")``````{r, echo = FALSE}gt::gt(head(iris)) |>  gt::tab_header("(\\#tab:label) Iris data set using `gt`, with special label")``````{r, echo = FALSE}knitr::kable(head(iris), caption = "Iris data set using `kable`")```

And here is the output that I currently have:

enter image description here

Transform the value of column to number of rows [duplicate]

$
0
0

I m new in R.I want to transform the column value to number of rows.

data:

Month         NumberMarch         1February      2February      2

The output i want is :

Month         NumberMarch         1February      1February      1February      1February      1

I try this code but he give me this

data %>%    ungroup %>%    uncount(Number)

SparkR: creating a Spark table with a nested data column

$
0
0

I'm working in Databricks trying to push data from an R notebook to Apache Spark where one column is nested data. Here's a working example without the nesting:

library(SparkR)sparkR.session()d1 = data.frame(id = 1:3, name = c('x', 'y', 'z'))# temp viewSparkR::dropTempView('temp1') # drop if it already existsSparkR::createOrReplaceTempView(SparkR::as.DataFrame(d1), 'temp1')my_schema1 = structType(structField("id", "double"), structField("name", "string"))SparkR::createTable('hive_metastore.my_project.test1', schema = my_schema1)# append data to spark tableSparkR::sql('INSERT INTO hive_metastore.my_project.test1 TABLE temp1;')# testSparkR::sql('SELECT * FROM hive_metastore.my_project.test1') |> SparkR::showDF()+---+----+| id|name|+---+----+|1.0|   x||2.0|   y||3.0|   z|+---+----+

Now a nested data example:

# 2 functions to generate equivalent nested data structuressub_fn1 = function(x) data.frame(key = base::sample(LETTERS, x), val = rnorm(x))sub_fn2 = function(x) purrr::map2(base::sample(LETTERS, x), rnorm(x), ~ list(key = .x, val = .y))d2 = dplyr::tibble(  id = 1:3, name = c('x', 'y', 'z'),  data1 = purrr::map(c(3, 5, 4), sub_fn1),  data2 = purrr::map(c(3, 5, 4), sub_fn2)) |> as.data.frame()dplyr::glimpse(d2)Rows: 3Columns: 4$ id    <int> 1, 2, 3$ name  <chr> "x", "y", "z"$ data1 <list> [<data.frame[3 x 2]>], [<data.frame[5 x 2]>], [<data.frame[4 x 2…$ data2 <list> [["I", 0.6562561], ["N", -0.5147073], ["M", -0.4036189]], [["M",…

I'm unable to create a valid schema to reflect either of these datax fields, so cannot specify the Spark table to append to. For example:

my_schema2 = structType(  structField("id", "double"),   structField("name", "string"),   structField("data2", "array"))Error in checkType(type) : Unsupported type for SparkDataframe: array

Are these examples of nesting supported? Very grateful for assistance to figure out how to get past "INSERT INTO" step with the example nested dataset.

Viewing all 207118 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>