Having a dataframe like this:
dframe <- structure(list(id = c(1L, 1L, 1L, 1L, 2L, 2L, 2L), name = c("Google",
"Google", "Yahoo", "Amazon", "Amazon", "Google", "Amazon"), date = c("2008-11-01",
"2008-11-02", "2008-11-01", "2008-11-04", "2008-11-01", "2008-11-02",
"2008-11-03")), class = "data.frame", row.names = c(NA, -7L))
And a list with names
list <- c("Google", "Yahoo", "Amazon")
How can I have an output like this:
id name date 1 Google 2008-11-01 1 Yahoo 2008-11-01 1 Amazon 2008-11-04 2 Amazon 2008-11-01 2 Google 2008-11-02
For every id keep from the list the first date. I tried this one:
library(data.table)
library(tidyverse)
library(reshape2)
library(zoo)
date_list_first= dframe[,head(.SD,1), by = .(id)]