R Data Frames
A Data Frame is a list of vectors which are of equal length. Data Frame accepts different data types (numeric, character, factor, etc.)
kodingwindow@kw:~$ R
...
> f <- c("Apple","Orange","Mango")
> c <- c("Red","Orange","Yellow")
> r <- c(200,100,500)
> q <- c(12,12,12)
> a <- c(FALSE,FALSE,TRUE)

> df <- data.frame(f,c,r,q,a)
> df
       f      c   r  q     a
1  Apple    Red 200 12 FALSE
2 Orange Orange 100 12 FALSE
3  Mango Yellow 500 12  TRUE

> names(df) <- c("Fruits","Colors","Rates","Quantity","Availability")
> df
  Fruits Colors Rates Quantity Availability
1  Apple    Red   200       12        FALSE
2 Orange Orange   100       12        FALSE
3  Mango Yellow   500       12         TRUE

> str(df)
'data.frame':	3 obs. of  5 variables:
 $ Fruits      : Factor w/ 3 levels "Apple","Mango",..: 1 3 2
 $ Colors      : Factor w/ 3 levels "Orange","Red",..: 2 1 3
 $ Rates       : num  200 100 500
 $ Quantity    : num  12 12 12
 $ Availability: logi  FALSE FALSE TRUE

Append a column to Data Frame
> t <- c("Sour","Bitter","Sweet")
> df$Taste <- t
> df
  Fruits Colors Rates Quantity Availability  Taste
1  Apple    Red   200       12        FALSE   Sour
2 Orange Orange   100       12        FALSE Bitter
3  Mango Yellow   500       12         TRUE  Sweet
Advertisement