R: Using equation with natural logarithm in nls

In R, log is the natural logarithm. In calculators, log usually means base 10 logarithm. To achieve that in R you can use the log10 function. As for your formula, it seems correct, since log is the natural logarithm.

Categories R

Set NA to 0 in R

You can just use the output of is.na to replace directly with subsetting: Or with a reproducible example: However, be careful using this method on a data frame containing factors that also have missing values: It “works”: …but you likely will want to specifically alter only the numeric columns in this case, rather than the … Read more

Categories R

Changing column names of a data frame

I have a data frame called “newprice” (see below) and I want to change the column names in my program in R. In fact this is what am doing: I have not put this in a loop because I want each column name to be different as you see. When I paste my program into … Read more

Categories R

adding x and y axis labels in ggplot2

[Note: edited to modernize ggplot syntax] Your example is not reproducible since there is no ex1221new (there is an ex1221 in Sleuth2, so I guess that is what you meant). Also, you don’t need (and shouldn’t) pull columns out to send to ggplot. One advantage is that ggplot works with data.frames directly. You can set … Read more

Categories R

Error in if/while (condition) {: missing Value where TRUE/FALSE needed

The evaluation of condition resulted in an NA. The if conditional must have either a TRUE or FALSE result. This can happen accidentally as the results of calculations: To test whether an object is missing use is.na(x) rather than x == NA. See also the related errors: Error in if/while (condition) { : argument is … Read more

Categories R

Remove legend ggplot 2.2

I’m trying to keep the legend of one layer (smooth) and remove the legend of the other (point). I have tried shutting off the legends with guides(colour = FALSE) and geom_point(aes(color = vs), show.legend = FALSE). Edit: As this question and its answers are popular, a reproducible example seems in order:

Categories R

What does na.rm=TRUE actually means?

Whenever we have NA in our data,we used na.rm=TRUE to get proper results for mean,mode etc. What does na.rm do? I could understand that rm is for remove,which we even use for deleting variables.But why have we written na in small? R is case sensitive?And what does Boolean value TRUE does here?

Categories R