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

  • Carlos Delgado

    Carlos Delga

    21 HAZİRAN 2011
  • lissaandbeauty

    lissaandbeau

    24 Aralık 2011
  • Pituvision

    Pituvision

    11 Mart 2006