Mean per group in a data.frame
This type of operation is exactly what aggregate was designed for: Here we aggregate columns 3 and 4 of data.frame d, grouping by d$Name, and applying the mean function. Or, using a formula interface:
This type of operation is exactly what aggregate was designed for: Here we aggregate columns 3 and 4 of data.frame d, grouping by d$Name, and applying the mean function. Or, using a formula interface:
It is unclear how you created those data.frames. From the str output they appear not to be ordinary data.frames but some other kind of lists, so it might be necessary to convert your objects to data.frames first. Use as.matrix(as.data.frame(vols)).
You can add your blank column, re-order, and sort using the code below:
Use outline = FALSE as an option when you do the boxplot (read the help!).
Your code has a number of issues: The if statement would need enclosing {} symbols. The if also needs enclosing () symbols around the logical expression. The result of the recode function is not stored anywhere (the function does not change values-in-place). Loops are a poor solution to this problem. It would be much simpler to take advantage of R’s natural vectorization. Rather than an if inside … Read more
Both the match() (returns the first appearance) and %in% (returns a Boolean) functions are designed for this.
Several sites provide reasonable cheat sheets or HOWTOs for tables and images. Top on my list are: Pandoc readme, specifically tables RStudio’s RMarkdown, more details in basics (including tables) and a rewrite of pandoc’s markdown. Pictures are very simple to use but do not offer the ability to adjust the image to fit the page (see Update, below). To adjust the image … Read more
tl;dr your model needs 4 parameters, but you only gave 3 parameters in the starting vector. I figured this out by (1) trying OLS(c(1,1,1),y=y,z=z) (to confirm that the return value is NA at the starting value); (2) setting debug(OLS) and stepping through it. When you step through the function checking values as you go you can see that sigma2 becomes NA, because k==3 (the model matrix has … Read more
For example if I have this: Then how do I combine the two columns n and s into a new column named x such that it looks like this:
Here is the full set of things you can change in element_text: