Monday, September 23, 2019

R: DataFrame: Selecting A Subset of a R Data Frame, merging.

Notes from the Tutorial "Meet The R Dataframe: Examples of Manipulating Data In R":

Use the ChickWeight dataset for this example

data("ChickWeight")


> head (ChickWeight)
  weight Time Chick Diet
1     42    0     1    1
2     51    2     1    1
3     59    4     1    1

Selecting A Subset of a R Data Frame
1. using the function subset
> subset(ChickWeight, Diet==4)

2. with a conditional indexing
> ChickWeight[ChickWeight$Diet==4,]

3. using the function which
> ChickWeight[which((ChickWeight$Diet == 4) & (ChickWeight$Time==21)), names(ChickWeight) %in% c("weight","Time")]