[Solved] Data selection error [closed]

Your code seems to be completely backwards to what you’re trying to achieve: “For each gene (in d2) which SNPs (from d1) are within 10kb of that gene?” First of all, your code for d1$matched is backwards. All your p‘s and d2s should be the other way round (currently it doesn’t make much sense?), giving … Read more

[Solved] How adjust code functionality to specifications using data.table function

With data.table, we can specify the .SDcols to select the ‘DR’ columns or ‘date_cols’ and assign back the output to those, then instead of using rowwise matching, use a row/column indexing to extract the values to create the ‘Result’ library(data.table) # get the column names that starts with DR dr_names <- grep(“^DR”, names(df1), value = … Read more

[Solved] Taking values from two/multiple matrices in R?

Re-arranging your data into matrices with rownames makes this more convenient, as the row names are not a column, and therefore do not force a mode of character for the numeric data. Here are how the matrices would look. I created meaningless column names for this example, in order to show which columns are used … Read more

[Solved] how to do a column split and dcast in r [duplicate]

Here is a tidyverse possibility library(tidyverse) df %>% separate_rows(Weather) %>% group_by(Date) %>% mutate(n = 1) %>% spread(Weather, n, fill = 0) ## A tibble: 6 x 4 ## Groups: Date [6] # Date Fog Rain Thunderstorm # <fct> <dbl> <dbl> <dbl> #1 2018-01-01 1. 1. 0. #2 2018-01-02 1. 1. 0. #3 2018-01-03 0. 1. … Read more

[Solved] how to apply a function on a data set?

I’m at least not quite sure whether I understood correct. Maybe a better question could improve the answers… DF <- data.frame(Tree = c(4382, 4383, 4384, 5385, 4386), a = c(21.88, 13.93, 19.69, 20.02, 11.07), b = c(9.59, 12.95, 9.78, 8.23, 23.20), k = c(0.0538, 0.0811, 0.0597, 0.0489, 0.1276)) DOY <- c(1:365) DF_new <- data.frame(sapply(1:length(DF$Tree), function(x)(DF$a[x]*exp(-exp(DF$b[x]-DF$k[x]*DOY))))) … Read more

[Solved] Selecting a unique value from an R data frame

Using data.table: (Edited to reflect @Frank’s comments) DT[, Benchmark := Value[Category == “Time”][which.min(Number[Category == “Time”])], by = FileName] Breaking this down: Number[Category == “Time”] Take all Number where Category == Time which.min(^^^) Find which one is the minimum Benchmark := Value[Category == “Time”][^^^] Set the new column of benchmark to the value at this minimum … Read more

[Solved] Create table with Distinct Account Number, first Date in R

A little heads up here, I will try to address this question by using the package data.table. I will also assume the data is in a data.table called LGD_data_update, as pointed out in your comment. So, you will need this. library(data.table) LGD_data_update <- data.table( LGD_data_update) In this case, you first need to sort the rows … Read more

[Solved] how to melt the dataframe in R

Creating some data to work with: tim <- data.frame(2616, 2617, 2388) colnames(tim) <- c(“Jun”, “Jul”, “Aug”) This is our data tim: Jun Jul Aug 1 2616 2617 2388 You can use the melt function and then select only the column you wish to keep. The following code: library(dplyr) library(reshape2) melt(tim, value.name = “Month”) %>% select(Month) … Read more

[Solved] Loop over NA values in subsequent rows in R [closed]

reproducible data which YOU should provide: df <- mtcars df[c(1,5,8),1] <-NA code: IND <- is.na(df[,1]) df[IND,1] <- df[dplyr::lag(IND,1L, F),1] * 3 since you use lag I use lag. You are saying “previous”. So maybe you want to use lead. What happens if the first value in lead case or last value in lag case is … Read more

[Solved] histogram and pdf in the same graph [duplicate]

h<-hist(data, breaks=”FD”, col=”red”, xlab=”xTitle”, main=”Normal pdf and histogram”) xfit<-seq(min(data),max(data),length=100) x.norm<-rnorm(n=100000, mean=a, sd=b) yfit<-dnorm(xfit,mean=mean(x.norm),sd=sd(x.norm)) yfit <- yfit*diff(h$mids[1:2])*length(loose_All) lines(xfit, yfit, col=”blue”, lwd=2) 1 solved histogram and pdf in the same graph [duplicate]

[Solved] Matrix operation in R: I have a square matrix whose determinant is zero, i need to find its inverse in R programing. Is it possible ,if yes how? [closed]

Matrix operation in R: I have a square matrix whose determinant is zero, i need to find its inverse in R programing. Is it possible ,if yes how? [closed] solved Matrix operation in R: I have a square matrix whose determinant is zero, i need to find its inverse in R programing. Is it possible … Read more