r

How to filter rows out of data.table where any column is NA without specifying columns individually

扶醉桌前 提交于 2021-02-11 05:21:09
问题 Given a data.table DT<-data.table(a=c(1,2,NA,4,5), b=c(2,3,4,NA,5),c=c(1,2,3,4,5),d=c(2,3,4,5,6)) how can I do the equivalent of DT[!is.na(a) & !is.na(b) & !is.na(c) & !is.na(d)] in a general form without knowing any of the column names or typing out the !is.na() for each individual column. I could also do DT[apply(DT,1,function(x) !any(is.na(x)))] but I'm wondering if there's a better way still. 回答1: I think you are looking for complete.cases : > DT[complete.cases(DT),] a b c d 1: 1 2 1 2 2:

How to filter rows out of data.table where any column is NA without specifying columns individually

大兔子大兔子 提交于 2021-02-11 05:17:07
问题 Given a data.table DT<-data.table(a=c(1,2,NA,4,5), b=c(2,3,4,NA,5),c=c(1,2,3,4,5),d=c(2,3,4,5,6)) how can I do the equivalent of DT[!is.na(a) & !is.na(b) & !is.na(c) & !is.na(d)] in a general form without knowing any of the column names or typing out the !is.na() for each individual column. I could also do DT[apply(DT,1,function(x) !any(is.na(x)))] but I'm wondering if there's a better way still. 回答1: I think you are looking for complete.cases : > DT[complete.cases(DT),] a b c d 1: 1 2 1 2 2:

How to filter rows out of data.table where any column is NA without specifying columns individually

放肆的年华 提交于 2021-02-11 05:16:35
问题 Given a data.table DT<-data.table(a=c(1,2,NA,4,5), b=c(2,3,4,NA,5),c=c(1,2,3,4,5),d=c(2,3,4,5,6)) how can I do the equivalent of DT[!is.na(a) & !is.na(b) & !is.na(c) & !is.na(d)] in a general form without knowing any of the column names or typing out the !is.na() for each individual column. I could also do DT[apply(DT,1,function(x) !any(is.na(x)))] but I'm wondering if there's a better way still. 回答1: I think you are looking for complete.cases : > DT[complete.cases(DT),] a b c d 1: 1 2 1 2 2:

Read binary vector

霸气de小男生 提交于 2021-02-11 05:09:13
问题 Imagine, I get a binary response from an API, which is a .rds object created with saveRDS() (R-version > 3.5). Basically the first five lines of the built in iris data set, like the cont object below: cont = as.raw(c(0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x85, 0x50, 0xb1, 0x4e, 0xc3, 0x30, 0x10, 0x75, 0x93, 0xba, 0x6d, 0x42, 0x40, 0xa8, 0xed, 0x6f, 0x90, 0x99, 0xad, 0x9e, 0x98, 0x18, 0x90, 0x0a, 0x82, 0xd5, 0x72, 0x9d, 0x62, 0xc9, 0x24, 0x95, 0x6d, 0x85, 0x95, 0xdf, 0x80

R- ode function (deSolve package): change the value of a parameter as a function of time

泪湿孤枕 提交于 2021-02-11 05:07:57
问题 I am trying to solve a first-order differential equation using the function ode from the deSolve package. The problem is as follows: a drug is administered by a constant infusion rate at some times (infusion times) and eliminated in a first-order rate. Thus, the process can be described by: if(t %in% Infusion_times){Infusion <- Infusion_rate} else{Infusion <- 0} dC <- -Ke*C + Infusion where t is the time, Infusion_times is a vector containing at what times the drug is administered, C is the

R- ode function (deSolve package): change the value of a parameter as a function of time

妖精的绣舞 提交于 2021-02-11 05:04:42
问题 I am trying to solve a first-order differential equation using the function ode from the deSolve package. The problem is as follows: a drug is administered by a constant infusion rate at some times (infusion times) and eliminated in a first-order rate. Thus, the process can be described by: if(t %in% Infusion_times){Infusion <- Infusion_rate} else{Infusion <- 0} dC <- -Ke*C + Infusion where t is the time, Infusion_times is a vector containing at what times the drug is administered, C is the

R- ode function (deSolve package): change the value of a parameter as a function of time

坚强是说给别人听的谎言 提交于 2021-02-11 05:04:07
问题 I am trying to solve a first-order differential equation using the function ode from the deSolve package. The problem is as follows: a drug is administered by a constant infusion rate at some times (infusion times) and eliminated in a first-order rate. Thus, the process can be described by: if(t %in% Infusion_times){Infusion <- Infusion_rate} else{Infusion <- 0} dC <- -Ke*C + Infusion where t is the time, Infusion_times is a vector containing at what times the drug is administered, C is the

Analyzing spatial data between two points in R using a very large data set

北城以北 提交于 2021-02-11 05:02:17
问题 This is my first time writing code in R from scratch and I'm struggling with how to approach it. I'm looking at turtle nests and their proximity to light sources (i.e. houses, light poles, etc.) to determine how often a light source is within a given radius of a nest. These are both very large data sets (hundreds of thousands of rows) so the code will likely need to run a loop for each nest position. GPS coordinates for both data sets are in decimal degrees. The nest data is essentially

Labeling: Facet grid with multiple lines of text on y label

℡╲_俬逩灬. 提交于 2021-02-11 04:58:39
问题 I have a plotly graph made in ggplot2. I am displaying the graphics using face_grid but the y axis is very long. Because of this not all the words on the y axis are visible. Is there a way to split the text into two lines such that the entire y axis is visible? majors.sub.HS<- majors.sub[, c(8:10, 66)] majors.sub.HS<-melt(majors.sub.HS, id.vars = "Major" ) majors.sub.HS$value[majors.sub.HS$value=="5- Highly Supported"] <- 5 majors.sub.HS$value[majors.sub.HS$value=="1- Not Supported"] <- 1

Read binary vector

狂风中的少年 提交于 2021-02-11 04:58:34
问题 Imagine, I get a binary response from an API, which is a .rds object created with saveRDS() (R-version > 3.5). Basically the first five lines of the built in iris data set, like the cont object below: cont = as.raw(c(0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x85, 0x50, 0xb1, 0x4e, 0xc3, 0x30, 0x10, 0x75, 0x93, 0xba, 0x6d, 0x42, 0x40, 0xa8, 0xed, 0x6f, 0x90, 0x99, 0xad, 0x9e, 0x98, 0x18, 0x90, 0x0a, 0x82, 0xd5, 0x72, 0x9d, 0x62, 0xc9, 0x24, 0x95, 0x6d, 0x85, 0x95, 0xdf, 0x80