tidyverse: data transformation, gather()

I am trying to transform a dataset: [1]: https://i.stack.imgur.com/09Ioo.png To something like this: [2]: https://i.stack.imgur.com/vKKu2.png How can I do this on R? I tried using gather() but somehow im not getting the results.. library(tidyverse) df_gather <- df %>% gather(key = "Day", "Sensor",2:5) View(df_gather) Thanks in advance for your help! >Solution : Because you did not… Read More tidyverse: data transformation, gather()

create two dataframes at once and joint their columns alternatively in R

assume this is my dataframe ( already created by a sequence of pipes ) df <- data.frame(month = c("May", "May","May","June","June","June", "July", "July","July"), rate = rep(c(0.3, 0.4, 0.5),times=3), a = c(5,4,3,10,9,8,20,19,18), b = c(100,200,300,1,2,3,10,20,30)) df month rate a b 1 May 0.3 5 100 2 May 0.4 4 200 3 May 0.5 3 300 4 June… Read More create two dataframes at once and joint their columns alternatively in R

How to remove duplicate column names in R?

I’ve got a big data frame, and like to remove the duplicate column For simplicity, let’s pretend this is my data: df <- data.frame(id1 = c("Aa","Aa","Ba","Ca","Da"), id2 = c(2,1,4,5,10), location=c(351,261,101,91,51), comment=c(35,26,10,9,5), comment=c(5,16,25,14,11), hight=c(15,21,5,19,18), check.names = FALSE) I can remove the duplicate column name "comment" using: df <- df[!duplicated(colnames(df))] However, when I apply same code in… Read More How to remove duplicate column names in R?

Problem with regex (check string for certain repetitions)

I would like to check whether in a text there are a) three consonants in a row or b) four identical letters in a row. Can someone please help me with the regular expressions? library(tidyverse) df <- data.frame(text = c("Completely valid", "abcdefg", "blablabla", "flahaaaa", "asdf", "another text", "a last one", "sj", "ngbas")) consonants <- c("q",… Read More Problem with regex (check string for certain repetitions)

case_when fails (unexpected results) but conditions for case_when work outside

I’m trying to apply some equations to get the proportion of a line (numeric array) that coincides with another line (another numeric array). I have a data frame with the required values and I try to create a new column with the percentage outcome based on how the two lines coincide. I have checked the… Read More case_when fails (unexpected results) but conditions for case_when work outside