subset

R caret: leave subject out cross validation with data subset for training?

☆樱花仙子☆ 提交于 2019-12-24 01:44:10
问题 I want to perform leave subject out cross validation with R caret (cf. this example) but only use a subset of the data in training for creating CV models. Still, the left out CV partition should be used as a whole, as I need to test on all data of a left out subject (no matter if it's millions of samples that cannot be used in training due to computational restrictions). I've created a minimal 2 class classification example using the subset and index parameters of caret::train and caret:

removing and appending elemets from and to a list based on a vector overlap

浪子不回头ぞ 提交于 2019-12-24 01:18:21
问题 I have a list with ~ 500 model objects. The names of this objects are v1: existing.list <- vector("list", 3) v1 <- names(existing.list) <- c("A", "B", "C") I now get different dataset, which i need to model, too, and save in the same list. The objects in this new dataset are overlapping with the some of the objects in existing.list . Because it is very time-consuming, i do want to keep the old results. The names of this new dataset are v2: v2 <- c("B", "C", "D") I first want to remove the

Keeping rows if any column matches one of a set of values

泪湿孤枕 提交于 2019-12-24 00:58:16
问题 I have a simple question about subsetting using R; I think I am close but can't quite get it. Basically, I have 25 columns of interest and about 100 values. Any row that has ANY of those values in at one of the columns, I want to keep. Simple example: Values <- c(1,2,5) col1 <- c(2,6,8,1,3,5) col2 <- c(1,4,5,9,0,0) col3 <- c('dog', 'cat', 'cat', 'pig', 'chicken', 'cat') df <- cbind.data.frame(col1, col2, col3) df1 <- subset(df, col1%in%Values) (Note that the third column is to indicate that

Removal of rows containing zero

流过昼夜 提交于 2019-12-24 00:37:04
问题 I have a dataset of variables Year Age Bag Computer 2008 0 4 4 2008 1 5 3 2008 2 5 12.5 2008 3 5 15 2008 4 5 33 2008 5 5 11 2008 85 5 3.5 2008 . . . 2008 108 0 0 2008 109 0 0 2008 110+ 0 0 I need to subset this in R in order to remove all the zero on my database and get this final table Year Age Bag Computer 2008 0 4 4 2008 1 5 3 2008 2 5 12.5 2008 3 5 15 2008 4 5 33 2008 5 5 11 2008 7 5 14.5 2008 8 5 17 without zero for the older ages. 回答1: If you want to identify the rows at which the 0

Create column identifying minimum character from within a group and label ties

守給你的承諾、 提交于 2019-12-23 23:09:38
问题 I have paired data for 10 subjects (with some missing and some ties). My goal is to select the eye with the best disc_grade (A > B > C) and label ties accordingly from the data frame below. I'm stuck on how to use R code to select the rows with the best disc_grade for each subject. df <- structure(list(patientID = c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10), eye = c("R", "L", "R", "L", "R", "L", "R", "L", "R", "L", "R", "L", "R", "L", "R", "L", "R", "L", "R", "L"), disc

Select values within/outside of a set of intervals (ranges) R

Deadly 提交于 2019-12-23 22:18:38
问题 I've got some sort of index, like: index <- 1:100 I've also got a list of "exclusion intervals" / ranges exclude <- data.frame(start = c(5,50, 90), end = c(10,55, 95)) start end 1 5 10 2 50 55 3 90 95 I'm looking for an efficient way (in R) to remove all the indexes that belong in the ranges in the exclude data frame so the desired output would be: 1,2,3,4, 11,12,...,48,49, 56,57,...,88,89, 96,97,98,99,100 I could do this iteratively: go over every exclusion interval (using ddply ) and

How to subset a dataframe and plot with leaflet depending on inputselect in shiny

别等时光非礼了梦想. 提交于 2019-12-23 22:18:33
问题 Using Rstudio I am trying to make a shiny app that produces leaflet outputs. Note that shiny is a package I have not used before so it could be that there are other mistakes in the script than the one I am currently encountering. I am using one dataframe with tracks of different individuals from which I want to subset and plot the track of one animal in response to inputselection. Sample: WhaleID lat long gm08_150c 68,4276 16,5192 gm08_150c 68,4337 16,5263 gm08_150c 68,4327 16,5198 gm08_154d

Subset one element of a row based on vector of column number

烈酒焚心 提交于 2019-12-23 21:24:32
问题 I have a dataset data <- cbind(c(1,2,3),c(1,11,21)) I want to extract one element from each row based on the column number given by a vector selectcol <- c(1,2,2) In that particular case the result should be result 1 11 21 I have tried resul<-apply(data, 1, [,selectcol]) but it does not work 回答1: You can use col to match the values with selectcol and subset data with it. data[col(data) == selectcol] # [1] 1 11 21 回答2: what if you try selection <- cbind(1:3, selectcol) result <- data[sel] 回答3:

What is the point of allowing a zero index when subsetting? [closed]

浪尽此生 提交于 2019-12-23 12:16:55
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed last year . Since R vector indices start at 1, what is the point of allowing indexing with zero: rivers[0] #numeric(0) This returns a zero length vector. Why not an error? How is this useful? 回答1: There aren't many use cases that crop up typically. I actually have one in the context of a package I'm developing for template

Find all sets/entities that are in another set [duplicate]

空扰寡人 提交于 2019-12-23 06:14:16
问题 This question already has answers here : Need a way to find matches between two many-to-many-relationships (3 answers) Closed last year . The answer is found in the abstract here but I'm looking for the concrete SQL solution. Given the following tables: ------------ ----------- | F_Roles | | T_Roles | ------+----- -----+----- | FId | RId| |TId | RId| ------+------ -----+----- | f1 | 2 | | t1 | 1 | | f1 | 3 | | t1 | 2 | | f2 | 2 | | t1 | 3 | | f2 | 4 | | t1 | 4 | | f2 | 9 | | t1 | 5 | | f3 | 6