I use Time Series data (imported with read.csv()
) and want to match()
values from an other data frame (also imported with read.csv
) to those recorded in my Time Series.
It looks like this:
df1 <- data.frame(hue=rawdata[,"hue"])
# This is my Time Series-raw data
hue
2017-07-01 00:00:00 0
2017-07-01 00:01:00 0
2017-07-01 00:02:00 0
2017-07-01 00:03:00 0
2017-07-01 00:04:00 0
2017-07-01 00:05:00 0
The Values change between 0 and 7 sometimes. Here's just a head()
print
And this is the data frame I want to check it with:
df2 <- data.frame(hue=sz$hue, Q=sz$Q)
# sz is the imported csv file
hue Q
1 0 0
2 1 13
3 2 26
4 3 39
5 4 52
6 5 65
Here, the same: Just a head()
print.
Now, my aim is to create a new column next to hue
in my rawdata.
in this new column I want the Q
-values depending on their hue
of df2
. For example: From minute Zero to five on 2017-07-01 the Q
-value in the new column will be 0, because hue
is 0.
I tried many things with the match
function like:
df1$match=sz$Q[match(df1$hue, sz$hue)]
But it's only working for the 0's and not for other values like 1,2,3 etc. R only gives me NA
s at those points.
It works perfectly in this Video: Using Match function in R
Actually I'm not quite sure if this is really a "match"-problem or a more format problem because I checked these two things:
> df1["2017-07-21 23:20:00","hue"]==2 # the value at this date is actually 2!
[1] FALSE
> is.numeric(df1["2017-07-21 23:20:00","hue"])
[1] TRUE
Does anyone know what I can do to get R to consider all values? Thank you so much for taking time for this!