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

  • Home
  • SEARCH
  • 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 9204685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:46:06+00:00 2026-06-17T23:46:06+00:00

I have a list called training_data. The training_data list contains data read from several

  • 0

I have a list called “training_data”. The “training_data” list contains data read from several files using the following function.

training_data <- lapply(files, read.table, header=TRUE, sep=",")

I can access the first field of any dataset using the following command:

training_data[[1]][1]           # The first field contains the class "pos OR neg"

I have to use these datasets (contained within training_data) for binary classification using Support Vector Machines (e1071). But the problem is that certain data sets contains only data for one class i.e either all pos or all neg, which is not acceptable for svm function and I want to exclude those datasets. I have tried the following code but unable to access the class column.

training_data<-lapply(training_data, 
                function(data)
                 {
                    if(["the class field is always positive"])
                       ### exclude this dataset from training_data

                 })

Update:
How exactly I can access the first column of data passed to function? And How can I exclude those data sets from training_data which consits of only one class in the class column?

Thanks

  • 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-17T23:46:07+00:00Added an answer on June 17, 2026 at 11:46 pm

    This is what the Filter function was made for. Since you didn’t provide replication code, here is a quick example on how to use Filter. Suppose you have a large list of vectors, each 2 elements in length:

    mylist <- lapply(1:1000, function(i) c(runif(1), runif(1)))
    

    Now if you want to only retain those vectors in the list where the first element is greater than 0.5, you would do something like this:

    filtered_list <- Filter(function (x) x[1] > 0.5, mylist)
    

    Now, if each element of mylist is a data.frame and the first column in each data.frame is the response vector for the model, as appears to be the case with your data, you can use the data[,1] notation mentioned by Justin to filter out all data.frames that have only positive or negative values in the first column:

    filtered_list <- Filter(function (x) { !(all(x[,1] < 0) || all(x[,1] > 0))}, 
                            mylist)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 datatables in a dataset. One table has a list called CostTypes.
I have a list URLs in a file called urls.txt . Each line contains
I have the following: A main List called GlobalStrings Another List called localStrings In
Let's say I have a list called list1 . This list1 contains another list,
I have a list called com, which contains a bunch of integers. I need
Hi i am using entity framework and LinQ. I have a table objects called
I have a list (called Within ), and it contains objects of type GameObject
I have a list called listitems which contains information on items. I want to
I have an object model MyObject that contains a list of long called ObjectList
I have a List called Registration and the following are the columns of my

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.