0

I would like to index a column based off a different columns values. I have a table of 2 columns, one is years, from 1990 to 2020, and another column, called Column X which is a corresponding value. I would like some code which indexes Column X from 1990 to year X, whereby I can chose which year to call to based off a singular input(year = ...)

I tried the following code below but that didn't work:

transform(data$value, data$Year == 2014)

NAFRO
  • 1
  • 1
  • can you provde a reproducible example so we know what the output should look like? – user1317221_G Jun 08 '23 at 09:44
  • `transform(data$value, ...)` works, but a more common way of using `transform` is to work on the frame itself and using the symbols of the columns, such as `transform(data, Year = 2014)`. There are a few confusing points here, though: (1) you mention "Column X", but it is not apparent in your code; (2) `transform` does assignments, but your code is just doing `Year == 2014` which is not an assignment, it returns a `logical` vector (this is likely an error); (3) you reference 1990 but then code 2014; ... – r2evans Jun 08 '23 at 13:10
  • Welcome to SO, NAFRO! Questions on SO (especially in R) do much better if they are reproducible and self-contained. By that I mean including attempted code (please be explicit about non-base packages), sample representative data (perhaps via `dput(head(x))` or building data programmatically (e.g., `data.frame(...)`), possibly stochastically), perhaps actual output (with verbatim errors/warnings) versus intended output. Refs: https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info. – r2evans Jun 08 '23 at 13:11

0 Answers0