首页 \ 问答 \ 如何从R环境中的ls()获取所有对象的dim()[重复](How to get the dim() of all of the objects obtaining from ls() in R environment [duplicate])

如何从R环境中的ls()获取所有对象的dim()[重复](How to get the dim() of all of the objects obtaining from ls() in R environment [duplicate])

这个问题在这里已经有了答案:

我想知道如何通过R ls()来获取有关所有objects信息。 举例来说,我想通过ls()函数知道所有列出对象的dim()

我做了以下,但它是不正确的!

lapply(ls(),dim)


This question already has an answer here:

I would like to know how I can get some information about all of the objects can be find through ls() in R. As example let's say I'd like to know the dim() of all of the listed objects through ls() function.

I did the following but it is not correct!

lapply(ls(),dim)


原文:https://stackoverflow.com/questions/43148871
更新时间:2023-07-02 11:07

最满意答案

Python支持一个内置的机制来处理列表,你可以很容易地做这样的事情:

list = []
list.append(10)
list.insert(0, 20)
list.append(30)
list.insert(1, 50)

有关更多示例,请参阅官方文档https://docs.python.org/3/tutorial/datastructures.html

无论如何,如果你想通过你的自我编程一个双链表,我已经对你的代码做了一些修改:

class createnode:
    def __init__(self, data):
        self.data = data
        self.next = None
        self.prev = None


class Unordered_list:
    def __init__(self):
        self.head = None

    def buildlst(self, data):
        node = createnode(data)
        if self.head is None:
            self.head = node
        else:
            node.next = self.head
            self.head.prev = node  # <---
            #  node.prev = None  <---- this is not necessary
            self.head = node

    def buildlstend(self, data):
        node = createnode(data)
        ptr = self.head
        while ptr.next:
            ptr = ptr.next
        ptr.next = node
        node.prev = ptr  # <---

    def insertbeforenode(self, data, srch_data):
        if srch_data == self.head.data: # <-- if you try to insert before the head
            self.buildlst(data)
        else:
            node = createnode(data)
            ptr = self.head
            while ptr:
                if ptr.data == srch_data:
                    node.prev = ptr.prev
                    node.next = ptr
                    ptr.prev = node
                    node.prev.next = node  # <--
                    break  # <--- when you find your node you have to quit from the loop
                else:
                    ptr = ptr.next

    def printlist(self):
        temp = self.head
        while (temp):
            print(temp.data)
            temp = temp.next

我已经把箭头(#< - )放在了我进行更改的地方。 在处理指针和其他错误时存在一些错误。 请试试这个,让我知道!


Python supports a built-in mechanism to work with lists, you could easily do something like this:

list = []
list.append(10)
list.insert(0, 20)
list.append(30)
list.insert(1, 50)

See the official documentation for more examples https://docs.python.org/3/tutorial/datastructures.html.

Anyway if you want to program a double linked list by your self I have made some changes to your code:

class createnode:
    def __init__(self, data):
        self.data = data
        self.next = None
        self.prev = None


class Unordered_list:
    def __init__(self):
        self.head = None

    def buildlst(self, data):
        node = createnode(data)
        if self.head is None:
            self.head = node
        else:
            node.next = self.head
            self.head.prev = node  # <---
            #  node.prev = None  <---- this is not necessary
            self.head = node

    def buildlstend(self, data):
        node = createnode(data)
        ptr = self.head
        while ptr.next:
            ptr = ptr.next
        ptr.next = node
        node.prev = ptr  # <---

    def insertbeforenode(self, data, srch_data):
        if srch_data == self.head.data: # <-- if you try to insert before the head
            self.buildlst(data)
        else:
            node = createnode(data)
            ptr = self.head
            while ptr:
                if ptr.data == srch_data:
                    node.prev = ptr.prev
                    node.next = ptr
                    ptr.prev = node
                    node.prev.next = node  # <--
                    break  # <--- when you find your node you have to quit from the loop
                else:
                    ptr = ptr.next

    def printlist(self):
        temp = self.head
        while (temp):
            print(temp.data)
            temp = temp.next

I have put an arrow (# <--) where I made the changes. There were a couples of mistakes on working with pointers and others inaccuracies. Please try this and let me know!

相关问答

更多
  • 我建议你可以用这段代码检查它是否是一个双链表: node = givenNode; if(givenNode->P1 == null || givenNode->P2 == null) // It can not be double link list (circular) else if(givenNode->p1->p2 == givenNode || givenNode->p2->p1 == givenNode) { //It is a double linked list } else { It ...
  • 每当数据首先插入列表时, Current将为null。 当您查找插入数据的位置时,检查Current != null是循环的结束。 检查一个空引用,它将告诉您将数据放在第一个项目中: if (Current == null) { _Head.Next.Data = Hold.Data; } else { Current.Next.Data = Hold.Data; } 您还可以让Current指向数据应该结束的节点而不是之前的节点: for (Current = FirstUnsorted; Cu ...
  • 当您调用insert_before ,如果给定节点是头部,则新节点将是新头部。 所以你需要传递head的地址才能修改它。 你现在拥有的是这样的: head | v ------ ------ ------ - 30 - ---> - 20 - ---> - 10 - ------ <--- ------ <--- ------ ^ ------ | - 70 - --- ...
  • 从您在评论中输出的输出看起来,在第二级看起来没有添加任何内容。 如果您希望在第二级添加节点,则会将它们添加到第一级。 我认为问题出在add子函数的底部: Student* StudentList::addChild(Student* node1, int num) { // rest of function. node1 is never modified return node1; } 您始终将节点输入返回到该函数。 我想在你的下面的代码中 newNode = sl->addNode( ...
  • Python支持一个内置的机制来处理列表,你可以很容易地做这样的事情: list = [] list.append(10) list.insert(0, 20) list.append(30) list.insert(1, 50) 有关更多示例,请参阅官方文档https://docs.python.org/3/tutorial/datastructures.html 。 无论如何,如果你想通过你的自我编程一个双链表,我已经对你的代码做了一些修改: class createnode: def __i ...
  • 你的函数insert_beginning有一个问题: var=(struct node *)malloc(sizeof(struct node)); var->data[100]=words[100] 通过这两行你想要复制words数组并将它放在列表的节点上:)但你实现是假的,你只需复制第100个char (这是数组的界限,因为第一个char开始于0,最后一个是99索引)从words数组到节点data 100th char。 您必须复制所有words内容,因此您可以使用strncpy函数来执行此操 ...
  • 如果有任何方法可以访问新删除的lastNode对象,则只需要将引用更新为null。 如果无法通过遍历列表来访问此节点,那么您不必担心它。 虽然,为了以防万一,进行这种清理是一种很好的做法。 You would only need to update the reference to null if there was any way to access the newly deleted lastNode object. If there is no way to reach this node by tr ...
  • 绘图总是有助于这些数据结构。 你目前有什么: 你正确设置t的next : t->set_next(n); 。 缺少的是它下面的箭头,它是: n->set_prev(t) 。 通常,在处理双向链表时,对set_next的调用应该总是(大部分时间)伴随着对set_next参数的set_next的调用。 这是因为双链表的属性: x->next == y 表示 y->prev == x , y->prev == x 表示 x->next == y 。 Drawing always helps with such d ...
  • public void insert(Link newNode) { if(head == null) { head = newNode; tail = newNode; } else { tail.next = newNode; newNode.prev = tail; tail = newNode; } } 顺便说一句,重命名你的类因为LinkedList与java.uti ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)