Skip to content
Prev 393386 / 398500 Next

Get data from a list of data frames

Hello, Stefano,

maybe the following example contains what you want to achieve:

Station1 <- data.frame(sensor = c("thermometer", "raingauge", 
"snowgauge", "anemometer"),
                        code = c(2583, 1478, 3178, NA))
Station2 <- data.frame(sensor = c("thermometer", "raingauge", 
"snowgauge", "anemometer"),
                        code = c(2584, 1479, 3179, 4453))
Station3 <- data.frame(sensor = c("thermometer", "raingauge", 
"snowgauge", "anemometer"),
                        code = c(2584, 1479, 3179, 4453))
Station4 <- data.frame(sensor = rev(c("thermometer", "raingauge", 
"snowgauge", "anemometer")),
                        code = c(2584, 1479, 3179, 4453))
Station5 <- data.frame(sensor = c("raingauge", "snowgauge", 
"thermometer", "anemometer"),
                        code = c(2584, 1479, 3179, 4453))

Total <- list("Station1"=Station1, "Station2"=Station2,
               Station3 = Station3, Station4 = Station4,
               Station5 = Station5)

select.stat <- paste0("Station", c(1, 4, 5))
select.sens <- "thermometer"

sapply(Total[select.stat], function(x, sens)
   x$code[x$sensor == sens], sens = select.sens)



  Hth --  Gerrit

---------------------------------------------------------------------
Dr. Gerrit Eichner                   Mathematical Institute, Room 212
gerrit.eichner at math.uni-giessen.de   Justus-Liebig-University Giessen
Tel: +49-(0)641-99-32104          Arndtstr. 2, 35392 Giessen, Germany
http://www.uni-giessen.de/eichner
---------------------------------------------------------------------

Am 15.12.2022 um 14:52 schrieb Stefano Sofia: