0

I am trying to make new datasets from an existing dataset. I want to split it by selecting specific rows to go in each dataset. I have managed to slice out the data I want using my.data %<% slice(). I have tried to create a new data frame using this format:

 ed_exp1 <- education[c(10:21),c(2,6:7)]

but I keep getting this error:

Error: Positive column indexes in `[` must match number of columns:
* `.data` has 8 columns.

How do I go about naming this slice/turning it into a dataset that I can do further analysis on?

r2evans
  • 141,215
  • 6
  • 77
  • 149
user12696197
  • 63
  • 1
  • 1
  • 6
  • 2
    Welcome to SO! Please make this question *reproducible*. This includes sample code (including listing non-base R packages), sample *unambiguous* data (e.g., `dput(head(x))` or `data.frame(x=...,y=...)`), and expected output. Refs: https://stackoverflow.com/questions/5963269, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/tags/r/info. – r2evans Jan 12 '20 at 14:26
  • 2
    As far as *"naming this ... into a dataset"*, do you mean `newdata <- mydata %>% slice(...)`? (BTW: `slice()` without arguments does *absolutely nothing*, it returns the input data unchanged.) – r2evans Jan 12 '20 at 14:26
  • 2
    In addition to a sample of your dataset, please provide versions of packages you are using. One way (though it can be a bit verbose) is to include the output of `sessionInfo()` or `devtools::session_info()` (and [format it as code](https://stackoverflow.com/editing-help#syntax-highlighting)). – r2evans Jan 12 '20 at 14:42
  • Hi! education[c(10:21),c(2,6:7)] should work on data frames.. I think there's something weird about your object / dataframe eduction, can you do str(education) and paste the output too? In addition to r2evans' points above – StupidWolf Jan 12 '20 at 19:46

0 Answers0