How to remove all whitespace from a string?
So ” xx yy 11 22 33 ” will become “xxyy112233”. How can I achieve this? 9 Answers 9
So ” xx yy 11 22 33 ” will become “xxyy112233”. How can I achieve this? 9 Answers 9
Can anyone tell me how to find the common elements from multiple vectors? a <- c(1,3,5,7,9) b <- c(3,6,8,9,10) c <- c(2,3,4,5,7,9) I want to get the common elements from the above vectors (ex: 3 and 9) 3 Answers 3
I have read a CSV file into an R data.frame. Some of the rows have the same element in one of the columns. I would like to remove rows that are duplicates in that column. For example: platform_external_dbus 202 16 google 1 platform_external_dbus 202 16 space-ghost.verbum 1 platform_external_dbus 202 16 localhost 1 platform_external_dbus 202 16 … Read more
This is meant to be a FAQ question, so please be as complete as possible. The answer is a community answer, so feel free to edit if you think something is missing. This question was discussed and approved on meta. I am using R and tried some.function but I got following error message: Error: could … Read more
I have a big performance problem in R. I wrote a function that iterates over a data.frame object. It simply adds a new column to a data.frame and accumulates something. (simple operation). The data.frame has roughly 850K rows. My PC is still working (about 10h now) and I have no idea about the runtime. dayloop2 … Read more
Working with a data frame similar to this: set.seed(100) df <- data.frame(cat = c(rep(“aaa”, 5), rep(“bbb”, 5), rep(“ccc”, 5)), val = runif(15)) df <- df[order(df$cat, df$val), ] df cat val 1 aaa 0.05638315 2 aaa 0.25767250 3 aaa 0.30776611 4 aaa 0.46854928 5 aaa 0.55232243 6 bbb 0.17026205 7 bbb 0.37032054 8 bbb 0.48377074 9 … Read more
I have some trouble to convert my data.frame from a wide table to a long table. At the moment it looks like this: Code Country 1950 1951 1952 1953 1954 AFG Afghanistan 20,249 21,352 22,532 23,557 24,555 ALB Albania 8,097 8,986 10,058 11,123 12,246 Now I would like to transform this data.frame into a long … Read more
I saw in a tutorial about regression modeling the following command: myFormula <- Species ~ Sepal.Length + Sepal.Width + Petal.Length + Petal.Width What exactly does this command do, and what is the role of ~ (tilde) in the command? 3 Answers 3
With this data frame (“df”): year pollution 1 1999 346.82000 2 2002 134.30882 3 2005 130.43038 4 2008 88.27546 I try to create a line chart like this: plot5 <- ggplot(df, aes(year, pollution)) + geom_point() + geom_line() + labs(x = “Year”, y = “Particulate matter emissions (tons)”, title = “Motor vehicle emissions in Baltimore”) The … Read more
I want to use dplyr::mutate() to create multiple new columns in a data frame. The column names and their contents should be dynamically generated. Example data from iris: library(dplyr) iris <- as_tibble(iris) I’ve created a function to mutate my new columns from the Petal.Width variable: multipetal <- function(df, n) { varname <- paste(“petal”, n , … Read more