Data partition in shiny using caret package

...i am working on machine learning project for that need to divide data in training and test .
for that i have used caret package for data partition.
i tried the following code for partition but didnt worked , can anyone tell me what changes i have to make so i can solve and proceed further for same data.
Code i have tried

  
   
 index <- reactive({
     
     createDataPartition(new$student, p = .80,
                                     list = FALSE,
                                     times = 1) 
 train10 <- renderTable({ new[index,]
     train10
 })
 test10 <-renderTable({ new[-index,]
 test10
 })
 })

Hi,

Although I don't know if the data in the variable new$student is valid, one mistake I see in the code is that you assign a reactive variable index, but when you call it, you don't call it as a reactive variable. You should use the brackets when calling them like so:

new[index(),]

I know it looks a bit weird, but in Shiny, reactive values are functions that store the value.

It's better next time to create a reprex (or create one if this didn't help), so we can more easily test the issue ourselves:

Hope this helps,
PJ

thank you i tried and able to save in index. how can i get for train10 and test10?

This topic was automatically closed 54 days after the last reply. New replies are no longer allowed.