I'm trying to achieve below data.frame with a R code, I can create individual value and then create the data frame and it works,
But how to create the data frame with below code in R. i tried and gets this error message
Code :
new.df<- data.frame(mean=sapply(cereals[4:16], mean, na.rm=TRUE), +
std_dev=sapply(cereals[4:16], sd, na.rm=TRUE), +
min=sapply(cereals[4:16], min, na.rm=TRUE), +
max=sapply(cereals[4:16], max, na.rm=TRUE), +
median=sapply(cereals[4:16], median, na.rm=TRUE), +
lenght=sapply(cereals[4:16], length), +
mis.val=sapply(cereals[4:16], function(x) sum(length(which(is.na(x))))) )
Error
new.df<- data.frame(mean=sapply(cereals[4:16], mean, na.rm=TRUE), +
-
std_dev=sapply(cereals[4:16], sd, na.rm=TRUE), +
Error: unexpected '=' in:
"new.df<- data.frame(mean=sapply(cereals[4:16], mean, na.rm=TRUE), +
std_dev="
min=sapply(cereals[4:16], min, na.rm=TRUE), +
Error: unexpected ',' in " min=sapply(cereals[4:16], min, na.rm=TRUE),"
max=sapply(cereals[4:16], max, na.rm=TRUE), +
Error: unexpected ',' in " max=sapply(cereals[4:16], max, na.rm=TRUE),"
median=sapply(cereals[4:16], median, na.rm=TRUE), +
Error: unexpected ',' in " median=sapply(cereals[4:16], median, na.rm=TRUE),"
lenght=sapply(cereals[4:16], length), +
Error: unexpected ',' in " lenght=sapply(cereals[4:16], length),"
mis.val=sapply(cereals[4:16], function(x) sum(length(which(is.na(x))))) )
Error: unexpected ')' in " mis.val=sapply(cereals[4:16], function(x) sum(length(which(is.na(x))))) )"
Data Frame are given below:
mean std_dev min max median lenght mis.val
calories 106.883117 19.4841191 50.00000 160.00000 110.00000 77 0
protein 2.545455 1.0947897 1.00000 6.00000 3.00000 77 0
fat 1.012987 1.0064726 0.00000 5.00000 1.00000 77 0
sodium 159.675325 83.8322952 0.00000 320.00000 180.00000 77 0
fiber 2.151948 2.3833640 0.00000 14.00000 2.00000 77 0
carbo 14.802632 3.9073256 5.00000 23.00000 14.50000 77 1
sugars 7.026316 4.3786564 0.00000 15.00000 7.00000 77 1
potass 98.666667 70.4106360 15.00000 330.00000 90.00000 77 2
vitamins 28.246753 22.3425225 0.00000 100.00000 25.00000 77 0
shelf 2.207792 0.8325241 1.00000 3.00000 2.00000 77 0
weight 1.029610 0.1504768 0.50000 1.50000 1.00000 77 0
cups 0.821039 0.2327161 0.25000 1.50000 0.75000 77 0
rating 42.665705 14.0472887 18.04285 93.70491 40.40021 77 0