How to make all values in a row after a specific value appears, NA in R

I have data in R that looks like this: T1 <- c(0,0,0,0,0) T2 <- c(1,0,0,0,0) T3 <- c(0,1,0,0,0) T4 <- c(1,1,0,NA,1) T5 <- c(0,1,0,NA,0) df <- data.frame(T1,T2,T3,T4,T5) T1 T2 T3 T4 T5 1 0 1 0 1 0 2 0 0 1 1 1 3 0 0 0 0 0 4 0 0 0 NA… Read More How to make all values in a row after a specific value appears, NA in R

How to shift values left in R so that first non-NA value propagates column 1

I am trying to create a new set of variables based on observations at 5 different time points. However, there is not an observation for each row at each time point. Assuming it looks something like this: X1 <- c(NA,NA,7,8,1,5) X2 <- c(NA,0,0,NA,3,7) X3 <- c(NA,2,3,4,2,7) X4 <- c(1,1,5,2,1,7) X5 <- c(2,NA,NA,4,3,NA) df <- data.frame(X1,X2,X3,X4,X5)… Read More How to shift values left in R so that first non-NA value propagates column 1

Attempt to read property id on bool in Laravel

i tried assigning a value to a variable in an if condition if ($hotel = Hotel::whereCode($this->hotelCode)->first() && $room = Room::whereRoomCode($value)->first()) { if ($hotel->room_id == $room->id) { return true; } } I get this error Attempt to read property "room_id" on bool meanwhile $hotel variable is not a boolean >Solution : Your code can be processed… Read More Attempt to read property id on bool in Laravel

Recoding existing column in R

I have dataframe containing following two columns Tumor_Barcode SEX MEL-JWCI-WGS-1 Male MEL-JWCI-WGS-11 Male MEL-JWCI-WGS-12 Female MEL-JWCI-WGS-13 Male I want to recode column Tumor_Barcode into third column Sample_ID and output should be as following. Tumor_Barcode Sex Sample_ID MEL-JWCI-WGS-1 Male ME001 MEL-JWCI-WGS-11 Male ME011 MEL-JWCI-WGS-12 Female ME012 MEL-JWCI-WGS-13 Male ME013 Is there anyway i can do it… Read More Recoding existing column in R

Recode continuous data into categorical data using is.na() and if_else() in R

I have a data frame and one of the columns contain both continuous data and NA. I want to recode all continuous data as one level of categorical data and the NA as another using if_else() and is.na(). How can I do it? Example data frame: df<-tibble(id=1:10,score=c(3,1,-3,-9,NA,NA,12,NA,5,NA)) How can I recode all the numbers into… Read More Recode continuous data into categorical data using is.na() and if_else() in R

Recode if string (with punctuation) contains certain text

How can I search through a character vector and, if the string at a given index contains a pattern, replace that index’s value? I tried this: List <- c(1:8) Types<-as.character(c( "ABC, the (stuff).\n\n\n fun", "meaningful", "relevant", "rewarding", "unpleasant", "enjoyable", "engaging", "disinteresting")) for (i in List) { if (grepl(Types[i], "fun", fixed = TRUE)) {Types[i]="1" } else… Read More Recode if string (with punctuation) contains certain text

recode data using dplyr::recode when variables habe a space

I have myColors <- c("red", "purple", "blue", "blue", "orange", "red", "orange") library(dplyr) recode(myColors, red="rot", blue="blau", purple="violett") However if my data have spaces in them this method does not work myColors <- c("Color red", "Color purple", "Color blue", "Color blue", "Color orange", "Color red", "Color orange") recode(myColors, Color red="rot", Color blue="blau", Color purple="violett") Is there anything… Read More recode data using dplyr::recode when variables habe a space