在列表中创建指标变量

问题描述

我有一个list,其中包含数字序列。我想创建一个list来指示所有非零元素,直到与定义的限制匹配的第一个元素为止。我还想创建一个list来指示第一个元素之后的所有非零元素,以匹配定义的限制。

我更喜欢基本的R解决方案。大概该解决方案将使用lapply,但我无法提出一个简单的解决方案。

下面是一个最小可重复的示例,其中极限为2:

my.limit <- 2
my.samples  <- list(0,c(1,2),c(0,1,1),2,3,4),3))

以下是两个需要的lists

within.limit  <- list(0,0),0))
outside.limit <- list(0,1))

解决方法

我们可以将<div class="polygon"> <div class="content"> Lorem ipsum </div> </div>参数与match一起使用,因为它是一个很大的数字(应大于列表的任何长度,由于某些原因我不能在此处使用nomatch。)

Inf

检查输出是否正确,如图所示:

within.limit1 <- lapply(my.samples,function(x) 
                 +(x > 0 & seq_along(x) <= match(my.limit,x,nomatch = 1000)))

outside.limit1 <- lapply(my.samples,function(x) 
                    +(seq_along(x) > match(my.limit,nomatch = 1000)))
,

我会

#!/usr/bin/env python3
import re

def main():


# Write a program that loops through lines of the file and then print any words that contain two vowels next to each other.
    a = open("text.txt","r")
    read = a.read()
    split = read.split(' ')
    words = re.findall(r'\s*?[aeiou]\S*',split,re.I)

for w in words:
    print(w)

a.close()
,
def ingest(file_name):
   if file_name.endswith('.csv'):
      df = pd.read_csv(file_name)
   else:
      df = pd.read_excel(file_name)
   return df


,

我们可以使用findInterval

lapply(my.samples,function(x) 
          +(x > 0 & seq_along(x) <= findInterval(my.limit,x)-1))

lapply(my.samples,function(x)  +(seq_along(x) > findInterval(my.limit,x)-1))

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...