subset

How to delete specific rows from a numpy array using a condition?

扶醉桌前 提交于 2019-12-13 00:54:32
问题 This is the code a = np.array([[ 0, 1], [ 3, 11], [4,2]]) This is what I tried a= a[a[0]>0,:] It works fine when I only have two elements, but anything more it throws an error.What I am trying to do is that in the first column if there's a value less than one than I need to delete that entire row. so the expected output is ([ 3, 11], [4,2]]) I was hoping for a solution which I could generalize even if there were more than 2 elements per item such as ([2,3,4,5], [8,2,4,6], [2,4,9,1], [5,3,2,0]

Removing dataframe outliers in R with `boxplot.stats`

吃可爱长大的小学妹 提交于 2019-12-13 00:16:13
问题 I'm relatively new at R, so please bear with me. I'm using the Ames dataset (full description of dataset here; link to dataset download here). I'm trying to create a subset data frame that will allow me to run a linear regression analysis, and I'm trying to remove the outliers using the boxplot.stats function. I created a frame that will include my samples using the following code: regressionFrame <- data.frame(subset(ames_housing_data[,c('SalePrice','GrLivArea','LotArea')] , BldgType ==

Fast matrix subsetting via '[': by rows, by columns or doesn't matter?

杀马特。学长 韩版系。学妹 提交于 2019-12-12 23:15:06
问题 Imagine we are trying to flip a square matrix and do not care if it will be flipped row- or columnwise. We have a couple of alternatives: flip.by.col <- function(x) x[, rev(seq_len(ncol(x)))] flip.by.row <- function(x) x[rev(seq_len(nrow(x))), ] These matrices are not equal, but, as I said, that can be ignored. The question is: is there any difference from a computational perspective? One can think of a possible argument: row or column subsetting is a low-level operation that utilizes how the

In R how can I split a dataframe by date

喜你入骨 提交于 2019-12-12 20:12:52
问题 I have a dataframe where one column is a date time (chron). I would like to split this dataframe into a list of dataframes split by the date part only. So each dataframe will have all the data for that day. I looked at split function but not sure how to use part of a column value? 回答1: say you have this data.frame : df <- data.frame(date=rep(seq.POSIXt(as.POSIXct("2010-01-01 15:26"), by="day", length.out=3), each=3), var=rnorm(9)) > df date var 1 2010-01-01 15:26:00 -0.02814237 2 2010-01-01

R: Subset a data frame based on times that are within a certain number of minutes of an observation window

梦想与她 提交于 2019-12-12 19:42:05
问题 Let's say I have a data frame with start and end time columns, a measurement column and a time of measurement column, like so: start end value time 9:01:00 9:02:00 30.6 2013-03-25 9:05:00 9:01:00 9:02:00 30.8 2013-03-25 9:15:00 9:46:00 9:46:00 28.2 2013-03-25 9:43:00 9:46:00 9:46:00 28.9 2013-03-25 9:53:00 10:54:00 10:59:00 13.4 2013-03-25 10:56:00 10:54:00 10:59:00 13.8 2013-03-25 11:56:00 How might one subset this data frame to include only rows for which the time column is within the start

Subsetting DataFrame in R by duplicate values for Year by lowest value for Rating

我是研究僧i 提交于 2019-12-12 19:23:00
问题 I have a data frame which looks like this > fitchRatings Country Month Year FitchLongTerm LongTermTransformed 1 Abu Dhabi 7 2007 AA 22 2 Angola 5 2012 BB- 12 3 Angola 5 2011 BB- 12 4 Angola 5 2010 B+ 11 5 Argentina 7 2010 B 10 6 Argentina 12 2008 RD 3 7 Argentina 8 2006 RD 3 8 Argentina 12 2005 RD 3 9 Argentina 6 2005 DDD 2 10 Argentina 1 2005 D 0 As you can see, for some Countries, there are multiple observations for a single year. I want to subset the DF so that I keep only one observation

Randomly draw rows from dataframe based on unique values and column values

痞子三分冷 提交于 2019-12-12 18:12:08
问题 I have a dataframe with many descriptor variables (trt, individual, session). I want to be able to randomly select a fraction of the possible trt x individual combinations but control for the session variable such that no random pull has the same session number. Here is what my dataframe looks like: trt <- c(rep(c(rep("A", 3), rep("B", 3), rep("C", 3)), 9)) individual <- rep(c("Bob", "Nancy", "Tim"), 27) session <- rep(1:27, each = 3) data <- rnorm(81, mean = 4, sd = 1) df <- data.frame(trt,

Calculating the occurrences of numbers in the subsets of a data.frame

谁都会走 提交于 2019-12-12 16:22:13
问题 I have a data frame in R which is similar to the follows. Actually my real ’df’ dataframe is much bigger than this one here but I really do not want to confuse anybody so that is why I try to simplify things as much as possible. So here’s the data frame. id <-c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3) a <-c(3,1,3,3,1,3,3,3,3,1,3,2,1,2,1,3,3,2,1,1,1,3,1,3,3,3,2,1,1,3) b <-c(3,2,1,1,1,1,1,1,1,1,1,2,1,3,2,1,1,1,2,1,3,1,2,2,1,3,3,2,3,2) c <-c(1,3,2,3,2,1,2,3,3,2,2,3,1,2,3,3,3

only taking certain values from a list in perl

血红的双手。 提交于 2019-12-12 13:42:10
问题 First I will describe what I have, then the problem. I have a text file that is structured as such ----------- Start of file----- <!--> name,name2,ignore,name4,jojobjim,name3,name6,name9,pop --> <csv counter="1"> 1,2,3,1,6,8,2,8,2, 2,6,5,1,5,8,7,7,9, 1,4,3,1,2,8,9,3,4, 4,1,6,1,5,6,5,2,9 </csv> -------- END OF FILE----------- I also have a perl program that has a map: my %column_mapping = ( "name" => 'name', "name1" => 'name_1', "name2" => 'name_2', "name3" => 'name_3', "name4" => 'name_4',

r - Error in tag$head: object of type 'closure' is not subsettable

﹥>﹥吖頭↗ 提交于 2019-12-12 13:12:47
问题 I got this error when I Run my Shiny app on my laptop. App worked before I added a line of code with library(git2r). Below my code. Can anyone assist? Thanks. ui.R league_desc <- c("Premier League","Serie A","Bundesliga","La Liga") shinyUI( fluidPage( headerPanel(h1('Football Statistics', align = "center"), h2('Data on the 4 main european football leagues. Period 2011 - 2015', align = "center")), sidebarPanel( h4('Selection Parameters', align = "center"), This is the initial part of my ui.R