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 8492349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:41:33+00:00 2026-06-10T22:41:33+00:00

I have a data set raw.data.2010 that needs several steps of subsetting with different

  • 0

I have a data set raw.data.2010 that needs several steps of subsetting with different animal species. I also need to name them accordingly after every filtering process. I wrote a simple code as below:

#Creating reproducible data######
site=rep(list("Q", "R", "S", "T"), each=500)
grid=sample(1:2, size=2000, replace=TRUE)
spp=rep(list("A", "B", "C", "D", "E"), each=400)
fate=sample(1:5, size=20000, replace=TRUE)
sex=rep(list("M","F"), each=2000)
weight=sample(85:140, size=2000, replace=TRUE)

raw.data=as.data.frame(cbind(site, grid, spp, fate, sex, weight))

### main codes#####
spp=c("A", "B", "C", "D", "E")
    for (i in spp){
        name=paste(i, "raw", sep=".", collapse="")
        filter=paste("select",i, sep="", collapse="")
        assign(filter, raw.data$spp==i)
        assign(name, raw.data[get(filter),])
    }

I checked the filters and they worked without problem. But the last line didn’t work so all the subsetted data I called returned NA. What was wrong? Thank you.

EDIT: Hi, thank you all for your advice. I edited my codes so it’s reproducible. Basically I would like to first filter my raw.data with spp. Then I can keep adding more filters to group them according to site, grid, fate…etc. I need to be able to access the filtered data individually so I can manipulate them for later use, ex. calculate weight and other measurements for different sex or age group. I want to be able to call A.raw, A.Q.data later.

Since I would like to analyze my data at different levels (e.g. population level, individual level, site/grid level), and be able to pool/split them according to my needs. That’s the purpose of this code. Hope my explanation doesn’t confuse you.

  • 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-10T22:41:35+00:00Added an answer on June 10, 2026 at 10:41 pm

    You will probably save yourself a lot of work and grief in the long run if you move away from using global variables with assign and get and instead work with lists (and remember to subset using [[ instead of $).

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

Sidebar

Related Questions

I have created a script that analyzes a set of raw data and converts
Here is the situation: I have a huge data set that I need quick
I have a data set that resembles this: id product_id size color price created_date
I have a data set that is around 700 rows with eight columns of
I have a data set that that I would like to call in a
I have a data set of item difficulties that correspond to items on a
I have a working perl script that grabs the data I need and displays
I have raw data in a custom image format (canot be changed) that is
I have some dirty input data that is being imported into a raw source
I have a data structure that I want to access / modify in different

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.