There is a data.frame, I print it with sapply
:
df <- data.frame(name=c("alice","becka","james","jeffery","john"),
sex=c("F","M","M","F","M"),
age=c(13,13,12,13,12),
height=c(56.5,65.3,57.3,62.5,69),
weight=c(84,98,83,84,99.5),stringsAsFactors = FALSE)
sapply(df,function(x){print(x)})
[1] "alice" "becka" "james" "jeffery" "john"
[1] "F" "M" "M" "F" "M"
[1] 13 13 12 13 12
[1] 56.5 65.3 57.3 62.5 69.0
[1] 84.0 98.0 83.0 84.0 99.5
name sex age height weight
[1,] "alice" "F" "13" "56.5" "84"
[2,] "becka" "M" "13" "65.3" "98"
[3,] "james" "M" "12" "57.3" "83"
[4,] "jeffery" "F" "13" "62.5" "84"
[5,] "john" "M" "12" "69" "99.5"
Why is the output not as follows:
[1] "alice" "becka" "james" "jeffery" "john"
[1] "F" "M" "M" "F" "M"
[1] 13 13 12 13 12
[1] 56.5 65.3 57.3 62.5 69.0
[1] 84.0 98.0 83.0 84.0 99.5
Why is there a data.frame at the end as part of whole output?
name sex age height weight
[1,] "alice" "F" "13" "56.5" "84"
[2,] "becka" "M" "13" "65.3" "98"
[3,] "james" "M" "12" "57.3" "83"
[4,] "jeffery" "F" "13" "62.5" "84"
[5,] "john" "M" "12" "69" "99.5"