R optional subset in function -


i have dataframe follows

    individual  species   pdays ... gdays  1   alpha       opuntia   4         9 2   alpha       physalis  4         10 3   beta        opuntia   3         9 4   beta        physalis  5         8 

where individual , species categorical factors. attempting write function can @ effects of species, , optionally individual. cannot figure out how optionally subset individual. far have:

 seed_germination <- function (dataframe, species, individual) {     mydata <- read.table(dataframe, header = true, sep = ",")     attach(mydata)   subset_mydata <- mydata[mydata$species == species, ]    subset_ind <- subset_mydata[subset_mydata$individual == individual, ]                        #ignored if individual not specified      }   test <- seed_germination(dataframe = 'test.csv', species = 'opuntia',                            individual = 'alpha') 

i have played around with

  if(missing(individual))       return() 

with various things in return() no avail.

am approaching wrong?


Comments

Popular posts from this blog

python - Healpy: From Data to Healpix map -

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -