For example, I have the following data frame, DF:
> print.data.frame(df)
age amount type
1 35 1 term
2 42 3 universal
3 51 2 term
4 38 5 whole
5 19 2 universal
6 45 3 term
7 63 7 whole
>
I want to use the head()
function to print just the first 6 rows of df, but when I run the code I get the following:
head(df)
> head(df)
>
However, if I use print.data.frame(head(df))
, it works as intended:
> print.data.frame(head(df))
age amount type
1 35 1 term
2 42 3 universal
3 51 2 term
4 38 5 whole
5 19 2 universal
6 45 3 term
>
Why doesn't head()
function work without using print.data.frame
?
Edit:
This is the code I used to create the data frame
age <- c(35, 42, 51, 38, 19, 45, 63)
amount <- c(1, 3, 2, 5, 2, 3, 7)
type <- c("term","universal","term","whole","universal","term","whole")
df<-data.frame(age,amount,type)