> Dear R users, > > I have a very basic query, but was unable to find a proper anwser. > > I have the following data.frame > > x y > 2 0.12 > 3 0.25 > 4 0.11 > 6 0.16 > 7 0.20 > > and, due to further calculations, I need the data to be stored as > > x y > 1 0 > 2 0.12 > 3 0.25 > 4 0.11 > 5 0 > 6 0.16 > 7 0.20 > 8 0 > > How do I do the transformation?
Let's suppose your original data frame is DF1. Then: DF2 <- data.frame(x=1:8,y=rep(0,8)) DF2$y[DF1$x] <- DF1$y But I'd recommend you use NA for the missing values, unless you have a good reason to code them as zero. > Many many thjanks in advance. You are welcome. Helios De Rosario -- Helios de Rosario Martínez Researcher INSTITUTO DE BIOMECÁNICA DE VALENCIA Universidad Politécnica de Valencia • Edificio 9C Camino de Vera s/n • 46022 VALENCIA (ESPAÑA) Tel. +34 96 387 91 60 • Fax +34 96 387 91 69 www.ibv.org Antes de imprimir este e-mail piense bien si es necesario hacerlo. En cumplimiento de la Ley Orgánica 15/1999 reguladora de la Protección de Datos de Carácter Personal, le informamos de que el presente mensaje contiene información confidencial, siendo para uso exclusivo del destinatario arriba indicado. En caso de no ser usted el destinatario del mismo le informamos que su recepción no le autoriza a su divulgación o reproducción por cualquier medio, debiendo destruirlo de inmediato, rogándole lo notifique al remitente. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.