Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9211425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:17:33+00:00 2026-06-18T01:17:33+00:00

I need some help with managing several SVM models in R. I have around

  • 0

I need some help with managing several SVM models in R. I have around 100 data files and I would like to read each file and subsequently train a model for that file using e1071 package. The names of all files are contained in one file so its easier to track each file. I have used the following code but couldn’t reach the solution.

x<-read.table("data.dat", header=F)
x=as.vector(t(x))
vectory <- vector(mode="list", length=length(x))
vectorz <- vector(mode="list", length=length(x))

for (i in 1:length(x))
{
x[i] <- substr(x[i], 3, 100)
#assign(gsub("-", "_", x[i]), read.table(x[i], header=T, #sep=","))
val <- gsub("-", "_", x[i])
vectory[[val]] <- read.table(x[i], header=T, sep=",")
data(vectory[[val]])
valmodel <- x[i]
paste(valmodel, "_model", sep="")
vectorz[[valmodel]] <- ksvm(label ~ ., data=vectory[[val]])
}

I am confused with what exactly do I need to do for a data function call and data parameter while calling ksvm function.

Regards

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:17:35+00:00Added an answer on June 18, 2026 at 1:17 am

    As Scott mentioned, your example isn’t reproducible (and the quetsion doesn’t make it clear what your problem is). I rewrote your code so that it is less confusing. It’s untested, so you may need to tweak it.

    file_names <- read.table("data.dat")[[1]]
    file_names <- substring(file_names, 3)
    file_names <- gsub("-", "_", file_names)
    training_data <- lapply(
      file_names,
      read.table,
      header = TRUE,
      sep    = ", "
    )
    svm_models <- lapply(
      training_data,
      function(data)
      {
        ksvm(label ~ ., data = data)
      }
    )
    

    General principles:

    Name your variables meaningfully. Call file names file_names, not x.

    If you are looping over lists (or vectors), use lapply (or llply from plyr), rather than using a for loop since this involves extra boilerplate code and creating dummy variables. Notice how you don’t need vectory or vectorz anymore.

    Separate the code for reading in data from the code for running the model. They are different tasks, and muddling the code together will muddle your thinking. (Also, when one model fails, you don’t want to have to read your data in again.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need some help with the following: I have several worksheets with the same structure
Need some help. I have a table with some columns..like name , phone etc...
Need some help... I have jasperserver 4.1 installed on my ubuntu. It runs via
Need some help, please. I have a line of horizontal thumbnails loaded as ONE
Need some help to solve this. I have a gridview and inside the gridview
Need some help from javascript gurus. I have one page where http://www.google.com/finance/converter is embedded
Need some help with a query.. I have three tables. Source id name 1
Need some help with DataFormatString in GridView. I have a Double value that needs
I have Java servlet-based web applications. I would like to implement some operations in
Need some help with a SQL query. I have three tables TestOptions, CreateScript and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.