0

I am new in R and already found a lot of answers on this site, but with this one, I am stuck. I have a table (in Excel, see image in link) that gives me a value (called c) based on class (0 to 6) and start date (17/2018, 1/7/2019, 1/7/2020 and so on). In my dataframe there is a colum 'date' and a column 'class'. For every row in the dataframe, I need to find the corresponding c-value (so if class = 2 and date = 15/10/2018, I need the value 659,86 in a new column).

I have to problems: - when importing the data in R, it sets an "X" before the date - I don't know how to do the lookup with dates (with exact values, I manage with merge).

Hope my question is clear and somebody can help me.

Thanks!

steven

enter image description here

Rui Barradas
  • 70,273
  • 8
  • 34
  • 66
steven
  • 1
  • 1
  • 2
    Please provide a reproducible example. See [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for excellent examples. Nobody wants to open an image and manually write in your data. You can display it or a subset of it using `dput`. – sempervent Nov 20 '19 at 12:33
  • Images are a really bad way of posting data (or code). Can you post sample data in `dput` format? Please edit **the question** with the output of `dput(df)`. Or, if it is too big with the output of `dput(head(df, 20))`. (`df` is the name of your dataset.) – Rui Barradas Nov 20 '19 at 12:58
  • Hi, I understand the image is not easy to process, but the only thing I have right now is that same information in an Excel-file and I couldn't find how to upload an Excel-table. I don't have any R-data or whatever to share with you. – steven Nov 20 '19 at 13:22
  • Use a package such as `xlsx` to read in your excel table. See [here](https://stackoverflow.com/questions/6099243/read-an-excel-file-directly-from-a-r-script) for some methods. Whichever method you use there should be a `check.names` parameter. Set that to `FALSE` and it will prevent adding the `X` in front of your column names. Then please provide the `dput` of a subset of your data so we can help you further. – sempervent Nov 20 '19 at 13:47

0 Answers0