Error in ggplot.data.frame : Mapping should be created with aes or aes_string

The error (in the title of the post) arises because you have too many arguments to ggplot. As the comments to the question note, the pipeline %>% implicitly includes the output from the left-hand side of the pipe as the first argument to the function on the righthand side. This code replicates the same kind of error. (I’ve … Read more

Categories R Tags

How can two strings be concatenated?

is the way to go. As the previous posters pointed out, paste can do two things: concatenate values into one “string”, e.g. where the argument sep specifies the character(s) to be used between the arguments to concatenate, or collapse character vectors where the argument collapse specifies the character(s) to be used between the elements of the vector to be … Read more

Categories R

How to find the statistical mode?

One more solution, which works for both numeric & character/factor data: On my dinky little machine, that can generate & find the mode of a 10M-integer vector in about half a second. If your data set might have multiple modes, the above solution takes the same approach as which.max, and returns the first-appearing value of the set of … Read more

Categories R

Having trouble setting working directory

The command setwd(“~/”) should set your working directory to your home directory. You might be experiencing problems because the OS you are using does not recognise “~/” as your home directory: this might be because of the OS, or it might be because of not having set that as your home directory elsewhere. As you have tagged the post … Read more

Categories R

Drop data frame columns by name

You can use a simple list of names : Or, alternatively, you can make a list of those to keep and refer to them by name : EDIT : For those still not acquainted with the drop argument of the indexing function, if you want to keep one column as a data frame, you do: drop=TRUE (or not … Read more

Categories R

Remove duplicated rows

just isolate your data frame to the columns you need, then use the unique function 😀

Categories R

Why do I get “number of items to replace is not a multiple of replacement length”

Because the number of items to replace is not a multiple of replacement length. The number of items to replace is the number of rows where is.na(combi$DT) & !is.na(combi$OD) which is less than the number of rows in combi (and thus the length of the replacement). You should use ifelse: N.B. the & !is.na(combi$OD) is redundant: if both are NA, the replacement will … Read more

Categories R