subset

Run glm.mids on a subset of imputed data from mice (R)

拈花ヽ惹草 提交于 2019-12-11 11:35:49
问题 I get an error when I try to run glm.mids on a subset of a mids imputation object: library(mice) imp2 = mice(nhanes) glm.mids( (hyp==2)~bmi+chl, data=imp2, subset=(age==1) ) gives the cryptic error message "Error in eval(expr, envir, enclos) : ..1 used in an incorrect context, no ... to look in" even though the syntax works with regular glm on the original dataset: glm( (hyp==2)~bmi+chl, data=nhanes, subset=(age==1) ) The documentation ?glm.mids doesn't specifically address subset but says

Subsetting data by multiple date ranges - R

对着背影说爱祢 提交于 2019-12-11 10:50:29
问题 I'll get straight to the point: I have been given some data sets in .csv format containing regularly logged sensor data from a machine. However, this data set also contains measurements taken when the machine is turned off, which I would like to separate from the data logged from when it is turned on. To subset the relevant data I also have a file containing start and end times of these shutdowns. This file is several hundred rows long. Examples of the relevant files for this problem: file:

keeping a row that meets one criterion and the row above it if it meets another

可紊 提交于 2019-12-11 10:45:52
问题 I have a data set similar to, but much longer and complex than, the following: df<-data.frame(ID = c(1,1,2,2,3,3,3), week = c(20,21,10,15,20,21,22), var1 = c(0,1,0,1,0,0,1)) ID week var1 1 1 20 0 2 1 21 1 3 2 10 0 4 2 15 1 5 3 20 0 6 3 21 0 7 3 22 1 I would like to create a new data frame that keeps all rows where var1=1 and keeps the previous row if the ID is the same and the week is exactly one less than the included row. The new data frame would look like this: ID week var1 1 1 20 0 2 1 21

How to plot a bloxplot in R with subsets

我只是一个虾纸丫 提交于 2019-12-11 10:38:33
问题 My data set "olympics" has 4 columns: case number, height, sport, and sex (female=F, male=M), and each row corresponds to an athlete. I need to produce a box plot comparing the height distributions among the male basketball players and male football players. (Both sports on a single plot, but with no others.) I have tried boxplot(olympics$height[olympics$sex == "M" & olympics$sport %in% c("basketball", "football")]) but I keep getting errors saying that finite ylim values are needed. How

subsetting df with repeated sequences

流过昼夜 提交于 2019-12-11 10:35:57
问题 I have searched high and low for a solution to this, but I cannot find one..... My dataframe (essentially a table of the no. 1 sports team by date) has numerous occasions where one or various teams would "reappear" in the data. I want to pull out the start (or end) date of each period at no. 1 per team. An example of the data could be: x1<- as.Date("2013-12-31") adddate1 <- 1:length(teams1) dates1 <- x1 + adddate1 teams2 <- c(rep("w", 3), rep("c", 8), rep("w", 4)) x2<- as.Date("2012-12-31")

Subset dataframe by rows according with logical condition applied to column

半腔热情 提交于 2019-12-11 10:23:24
问题 This might be a trivial question, but I´m stuck on it since days without finding useful help in previous discussions. I have a data.frame like this: pho 23 3 23 4 5 6 7 fat pho 24 5 6 7 8 8 2 rew pho 2 3 4 5 6 7 6 ogd caf 23 34 5 6 78 4 tre caf 45 56 76 6 5 5 tre fra 3 4 5 6 2 4 rfe fra 4 65 76 78 3 2 ytr fra 54 6 7 8 23 5 rte I would like to subset the data.frame in order to keep together only the rows which have similar [1,1] element. I would like to store these new data.frames in a list,

R: Err: only 0's may be mixed with negative subscripts

旧时模样 提交于 2019-12-11 10:08:02
问题 Apparently I am trying to subset my variable with positive and "negative indexes". However debugging the code, I can not why R studio is interpreting it as I am mixing negative and positive subsets. Here is the part of the code: if (stepcount > 192 | sum(na.omit(ppt[i-193:i-1])) < 0.6) {statement} Error: Error in ppt[i - 193:i - 1] : only 0's may be mixed with negative subscripts Debugging the code I see that my value for i at this point is 3572 which means nor negative subsetting in ppt[i -

selecting rows in a data.frame in which a certain column has values containing one of a set of prefixes

血红的双手。 提交于 2019-12-11 10:03:18
问题 I have a data.frame of the type: > head(engschools) RECTYPE LEA ESTAB URN SCHNAME TOWN PCODE 1 1 919 2028 138231 Alban City School n.a. E1 3RR 2 1 919 4003 138582 Samuel Ryder Academy St Albans AL1 5AR 3 1 919 2004 138201 Hatfield Community Free School Hatfield AL10 8ES 4 2 919 7012 117671 St Luke's School n.a BR3 7ET 5 1 919 2018 138561 Harpenden Free School Redbourn AL3 7QA 6 2 919 7023 117680 Lakeside School Welwyn Garden City AL8 6YN And a set of prefixes like this one: >head(prefixes) E

How to select rows in an R data frame based on values of previous rows

情到浓时终转凉″ 提交于 2019-12-11 10:03:14
问题 I have what seems to be a simple problem which I haven't been able to solve. I have an R data frame which consists of a single column of data points, as show below. I would like to subset into a new data frame which contains data points based on value of previous data points. So below, I would for example like to subset all the rows where the previous value was greater than .04. Any ideas would be appreciated. Thank you. Price [1,] -0.006666667 [2,] 0.040268456 [3,] 0.051612903 [4,] -0

Subset a dataframe between two time periods

微笑、不失礼 提交于 2019-12-11 10:02:01
问题 If I have an example dataframe: Date <- c("05/12/2012 05:17:00", "05/12/2012 06:10:00", "05/12/2012 06:12:00", "05/12/2012 06:14:00", "06/12/2012 05:25:00", "06/12/2012 06:55:00", "06/12/2012 06:19:00", "06/12/2012 08:00:00", "07/12/2012 05:00:00", "07/12/2012 05:19:00", "07/12/2012 06:04:00", "07/12/2012 06:59:00") Date <- strptime(Date, "%d/%m/%Y %H:%M") a <- sample(12) hour <- as.numeric(format(Date, "%H")) min <- as.numeric(format(Date, "%M")) / 60 hours_mins <- hour + min df1 <- data