subset

Find all subsets that sum to a particular value and then pick the most valuable combination of those subsets

半世苍凉 提交于 2021-02-08 04:48:38
问题 Im trying to create a simple dice game. To calculate the score i have to find all subsets that sum to a particular value and then pick the most valuable combination. All numbers can only be picked once. Probably easiest to describe with an example: Values = {1, 1, 1, 2, 4, 4} Target value = 5 Possible subsets = {1, 1, 1, 2} and {1, 4} Now its possible to either choose: {1, 1, 1, 2} (= worth 5) or {1, 4} {1, 4} (= worth 10) So in this example I would like the algorithm to return 10 and not 5 .

subsetting a data.table based on a named list

若如初见. 提交于 2021-02-07 12:48:20
问题 I'm trying to subset a given data.table DT <- data.table( a = c(1:20), b = (3:4), c = (5:14), d = c(1:4) ) within a function by a parameter which is a named list param <- list(a = 1:10, b = 2:3, c = c(5, 7, 10)) I am maybe a bit stuck here but I certainly do not want implement something ugly like this. Especially since its not very dynamic. DT[(if (!is.null(param$a)) a %in% param$a else TRUE) & (if (!is.null(param$b)) b %in% param$b else TRUE) & (if (!is.null(param$c)) c %in% param$c else

How to subset all rows in a dataframe that have a particular value

你说的曾经没有我的故事 提交于 2021-02-05 12:25:22
问题 I have a large dataset that contains in each row different combinations of "NA" "1" and "2". I would like to subset all rows that specifically contain only "2" and "NA". So in the sample below, I'd like to automatically name and subset Row1 and Row4: df <- data.frame(Col1=c(NA,NA,2,NA), Col2=c(NA,NA,1,2), Col3=c(NA,1,NA,NA), Col4=c(2,NA,NA,NA), row.names=c("Row1","Row2","Row3","Row4"), stringsAsFactors = FALSE) 回答1: Try this: target <- 2 #print row names names(which(apply(df, 1, function(x)

How to subset all rows in a dataframe that have a particular value

旧时模样 提交于 2021-02-05 12:23:50
问题 I have a large dataset that contains in each row different combinations of "NA" "1" and "2". I would like to subset all rows that specifically contain only "2" and "NA". So in the sample below, I'd like to automatically name and subset Row1 and Row4: df <- data.frame(Col1=c(NA,NA,2,NA), Col2=c(NA,NA,1,2), Col3=c(NA,1,NA,NA), Col4=c(2,NA,NA,NA), row.names=c("Row1","Row2","Row3","Row4"), stringsAsFactors = FALSE) 回答1: Try this: target <- 2 #print row names names(which(apply(df, 1, function(x)

subsetting all elements of a list by the same index values [duplicate]

喜你入骨 提交于 2021-02-05 11:19:06
问题 This question already has answers here : Subset a list (choose matching values for all components) (2 answers) Closed 5 years ago . Probably trivial, but I didn't find a solution. I am trying to subset all elements of a list by the same index values. Assuming my list is: mylist = list( seq(22,30,2), c(1:5), rep(8,5)) which gives me [[1]] [1] 22 24 26 28 30 [[2]] [1] 1 2 3 4 5 [[3]] [1] 8 8 8 8 8 I am trying to extract only the values [2:4] and drop the other values of the element, so i get a

subsetting all elements of a list by the same index values [duplicate]

徘徊边缘 提交于 2021-02-05 11:18:28
问题 This question already has answers here : Subset a list (choose matching values for all components) (2 answers) Closed 5 years ago . Probably trivial, but I didn't find a solution. I am trying to subset all elements of a list by the same index values. Assuming my list is: mylist = list( seq(22,30,2), c(1:5), rep(8,5)) which gives me [[1]] [1] 22 24 26 28 30 [[2]] [1] 1 2 3 4 5 [[3]] [1] 8 8 8 8 8 I am trying to extract only the values [2:4] and drop the other values of the element, so i get a

subset dataset based on date comparison R

拈花ヽ惹草 提交于 2021-02-05 06:52:10
问题 I have a dataset as shown below Col1 Col2 Col3 CutoffDate 12001 Yes 2008-08-15 2008-08-10 12001 Yes 2008-08-22 2008-08-10 12001 Yes 2008-08-10 2008-08-10 12001 Yes 2008-08-04 2008-08-10 I am only interested in retaining the last two rows because they are less than or equal to the Cutoff Date 2008-08-10 . The final dataset should look like this Col1 Col2 Col3 CutoffDate 12001 Yes 2008-08-10 2008-08-10 12001 Yes 2008-08-04 2008-08-10 I know the subset function in R but not sure how to do this ,

How to filter dataframe with multiple conditions?

我与影子孤独终老i 提交于 2021-02-04 05:57:07
问题 I have this dataframe that I'll like to subset (if possible, with dplyr or base R functions): df <- data.frame(x = c(1,1,1,2,2,2), y = c(30,10,8,10,18,5)) x y 1 30 1 10 1 8 2 10 2 18 2 5 Assuming x are factors (so 2 conditions/levels), how can I subset/filter this dataframe so that I get only df$y values that are greater than 15 for df$x == 1 , and df$y values that are greater than 5 for df$x == 2 ? This is what I'd like to get: df2 <- data.frame(x = c(1,2,2), y = c(30,10,18)) x y 1 30 2 10 2

How to filter dataframe with multiple conditions?

冷暖自知 提交于 2021-02-04 05:56:08
问题 I have this dataframe that I'll like to subset (if possible, with dplyr or base R functions): df <- data.frame(x = c(1,1,1,2,2,2), y = c(30,10,8,10,18,5)) x y 1 30 1 10 1 8 2 10 2 18 2 5 Assuming x are factors (so 2 conditions/levels), how can I subset/filter this dataframe so that I get only df$y values that are greater than 15 for df$x == 1 , and df$y values that are greater than 5 for df$x == 2 ? This is what I'd like to get: df2 <- data.frame(x = c(1,2,2), y = c(30,10,18)) x y 1 30 2 10 2

遥感图像处理

旧时模样 提交于 2021-02-03 11:02:21
2021年第一篇文章 基本概念 遥感 (Remote Sensing):遥远的感知,是一种远距离不直接接触物体而获取其信息的探测技术,主要是以电磁波为媒介,包括从紫外--可见光--红外--微波的范围。 DN值 (Digital Number ):遥感影像像元亮度值,记录地物的灰度值。 地表反射率 (Surface Albedo):地面反射辐射量与入射辐射量之比,表征地面对太阳辐射的吸收和反射能力。反射率越大,地面吸收太阳辐射越少;反射率越小,地面吸收太阳辐射越多。 表观反射率 (Apparent Reflectance):指大气层顶的反射率,辐射定标的结果之一,大气层顶表观反射率,简称表观反射率,又称视反射率。 亮度温度 (Brightness Temperature):是指和被测物体具有相同辐射强度的黑体所具有的温度,简称亮温。 地理编码 (Geo-coding):把图像矫正到一种统一标准的坐标系。 地理参照 (Geo-referencing):又叫图像纠正(Rectification),借助一组控制点,对一幅图像进行地理坐标的校正。 图像配准 (Registration):同一区域里一幅图像(基准图像)对另一幅图像校准,以使两幅图像中的同名像素配准。 图像存储方式 一般,传感器获取的遥感图像,包括通用型的二进制数据和一个说明性的头文件。 二进制数据形式主要有三种,分别是BIL