How do i convert a Named num [1:4] to a data frame in R?
newbie to r, taking The R Programming Environment from coursera. one of the assignments is to select some columns from a data frame and find the means.
the code below seems to get the correct answer, but the answer should be a data frame.
wc_2 - worldcup %%
select(Time, Passes, Tackles, Saves) %%
colMeans()
How do i convert this to a data frame? i tried: wc_2-as.data.frame(wc_2)
but that gets it column wise. i do not see any way to pass the rows and columns or do a transpose in what i assume is a data frame constructor.
perhaps this can be done as part of the pipe?
thanks
edit: i got it to work:
means - worldcup %%
select(Time, Passes, Tackles, Saves) %%
colMeans()
wc_2-data.frame(t(matrix(means)))
colnames(wc_2)-names(means)
Category Data Science