SORU
9 Kasım 2009, PAZARTESİ


Her satır için bir R dataframe içinde

Bir dataframe var, ve bu dataframe her satır için bazı karmaşık aramalar yapmak ve bir dosya için bazı veri eklemek var.

Bu dataFrame 96 plaka gibi bir şey yapmak istiyorum yani biyolojik araştırmada kullanılan: seçili wells için bilimsel sonuçlar içerir

for (well in dataFrame) {
  wellName <- well$name    # string like "H1"
  plateName <- well$plate  # string like "plate67"
  wellID <- getWellID(wellName, plateName)
  cat(paste(wellID, well$value1, well$value2, sep=","), file=outputFile)
}

Usul benim dünyamda, bir şey yap:

for (row in dataFrame) {
    #look up stuff using data from the row
    #write stuff to the file
}

""Ne için bu? R yolu nedir

CEVAP
9 Kasım 2009, PAZARTESİ


Bu, apply() fonksiyon kullanmayı deneyebilirsiniz

> d
  name plate value1 value2
1    A    P1      1    100
2    B    P2      2    200
3    C    P3      3    300

> f <- function(x, output) {
 wellName <- x[1]
 plateName <- x[2]
 wellID <- 1
 print(paste(wellID, x[3], x[4], sep=","))
 cat(paste(wellID, x[3], x[4], sep=","), file= output, append = T, fill = T)
}

> apply(d, 1, f, output = 'outputfile')

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:
R

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • adrianisen

    adrianisen

    25 Kasım 2009
  • Andrea Lewis

    Andrea Lewis

    14 Mart 2013
  • How To Cook That

    How To Cook

    16 NİSAN 2011