Etimada Mirian Alzate Intente aplicar la formula a todos los datos, sin filtrar por fecha, si esta le da resultados puede mejorarla con el filtrado por fechas.
Javier Rubén Marcuzzi El mar., 23 oct. 2018 a las 9:49, <miriam.alz...@unavarra.es> escribió: > He comprobado que tiene formato fecha y sí que lo tiene: me dice formato > POSIxt. Al pasar la función me dice esto: > Empty data.table (0 rows) of 2 cols: Product.Id,rating.sem > > Gracias de nuevo > > > El Lun, 22 de Octubre de 2018, 21:06, Carlos Ortega escribió: > > Pues: > > > > 1. Que entre esos rangos de fechas haya un NA. > > La forma de protegerse es indicándoselo al cálculo de la media. > > datos[Fecha >= '2016-12-21' & Fecha <= '2016-12-28',.(rating.sem = > > mean(Rating, *na.rm =TRUE* )),by=Id.producto] > > > > 2. Que las fechas, tu variable "Fecha" no sea realmente una fecha. > > Compruébalo con class(datos$Fecha). > > > > Saludos, > > Carlos Ortega > > www.qualityexcellence.es > > > > > > > > El lun., 22 oct. 2018 a las 20:34, Miriam Alzate > > (<miriam.alz...@unavarra.es>) > > escribió: > > > >> Muchas gracias por la respuesta pero me da NA. ¿Qué puede ocurrir? > >> > >> Un saludo > >> > >> > >> El 22/10/2018 a las 20:12, Jesús Para Fernández escribió: > >> > Puedes hacerlo pasando tus datos a data.frame > >> > > >> > library(data.table) > >> > datos <- data.table(datos) > >> > datos[Fecha >= '2016-12-21' & Fecha <= '2016-12-28',.(rating.sem = > >> > mean(Rating)),by=Id.producto] > >> > > >> > Un saludo > >> > Jesús > >> > > >> > Obtener Outlook para Android <https://aka.ms/ghei36> > >> > > >> > > >> > > >> > De: Miriam Alzate > >> > Enviado: lunes, 22 de octubre 19:27 > >> > Asunto: [R-es] Agregar variable entre dos fechas > >> > Para: r-help-es > >> > > >> > > >> > Buenas, Tengo un dataframe con 64.000 observaciones llamado Datos y > >> > las variables "Id.Producto","Fecha"y "Rating" . La variable fecha > >> > tiene el formato: 2016-12-28 (ymd). Quiero crear la variable: > >> > "Rating.Semanal" - Esta variable tiene que ser la media agregada por > >> > "Id.Producto" de la variable "Rating", solo teniendo en cuenta > >> > aquellas observaciones que estén entre el "2016-12-21" y "2016-12-28". > >> > Muchas gracias Miriam _______________________________________________ > >> > R-help-es mailing list R-help-es@r-project.org > >> > https://stat.ethz.ch/mailman/listinfo/r-help-es > >> > > >> > >> > >> [[alternative HTML version deleted]] > >> > >> _______________________________________________ > >> R-help-es mailing list > >> R-help-es@r-project.org > >> https://stat.ethz.ch/mailman/listinfo/r-help-es > >> > > > > > > -- > > Saludos, > > Carlos Ortega > > www.qualityexcellence.es > > > > _______________________________________________ > R-help-es mailing list > R-help-es@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-help-es > [[alternative HTML version deleted]] _______________________________________________ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es