将大列表转换为一列包含所有元素的小标题[重复]

Posted

技术标签:

【中文标题】将大列表转换为一列包含所有元素的小标题[重复]【英文标题】:Transform a large list into a tibble with one column containing all elements [duplicate] 【发布时间】:2020-04-29 10:52:21 【问题描述】:

我很抱歉这个问题,因为它看起来很明显,但我自己无法提出解决方案。我有一个包含 130 个元素的大列表,每个元素包含 10 个单个字符串。

我想把它作为一个包含所有字符串的一列的组合小标题。

如果我在列表中尝试do.call(dplyr::bind_rows, y),我仍然会收到错误消息:Error: Argument 1 must have names

为了更深入地了解该列表,我将通过调用 dput(bribe.test[[1]]) 发布第一个子列表的控制台输出

dput(bribe.test[1])
list(list("\r\n                    Supercharge your R/C vehicle and also this systems will boost horsepower and performance of any RC nitro engines, visit us to get online xtm racing, xtm racing rail, xtm racing engine, xtm xt2 engine, and xtm nitro engine. Visit @ https://rbinnovations.com/collections/super-chargers/xtm-racing\r\n                  ", 
    "\r\n                    The Powermatic 2+ or Powermatic 2 Plus Electric Cigarette Rolling Machine uses an electric spoon-fed cigarette injector that will make king size or 100's cigarettes in a few seconds and you can buy it online with us at Hard Working Products. Visit https://hardworkingproducts.com/powermatic-2\r\n                  ", 
    "\r\n                    Hello sir, My uncle just coming india yesterday night at ahmedabad airport from New Zealand. And i gave him 2 iphone , iphone 8 plus and iphone 11 pro.. and they called by custom department. The officer told him that they are not allowed with these phone. They force him to pay 42,000/- custom duty for these phone. He just arrived that's why they haven't got money at that time. But his son gave him 600 nzd for his expenses. And these bloody corrupt office force him to pay 600$. They felt helpless at that time and gave 600$ with the passport.My uncle dont know his name. You can check cameras if you want, he was at counter around 1:00 o'clock at night. It is bloody bad experience with them. I'm going to tell my friends and all the relatives which are here to not go india ever..\nI'm felling helpless to come my home country. If you can then take strict actions against these bloody corrupt officers who are cheating with our nation. Please take strict action. Hope you can save our nation from this corrupt officers\nSingapor airlines \nSQ530 arrived at 21:50 evening on 6/1/20\nThank you\r\n                  ", 
    "\r\n                    Date of the incident: 29th December 2019\nTime of incident: Around 8 PM in the evening\nPlace of incident: ECR road, Pondicherry to Tamil Nadu check post.\nWhile driving back from Pondicherry to our stay near ECR road, we (4 people in the car) took 8 beer cans of 500 ml each. At the checkpost (just 100mtrs before our lodge) police stopped us, started checking the vehicle. We voluntarily declared the beer quantity and handed over to them.\nThey asked us to pay Rs 4200 and go else, they will create a case on us and arrest us, seize the vehicle. Since we took the vehicle from self drive agency, we really wanted come out of this. We apologise to them as we weren't aware of the border lines between the states. Requested them to dispose the beers and let us go. My 5 year old daughter was crying seeing the officers are not allowing me to leave. Nothing was fruitful and we literally beg them to leave us. Language was a big barrier as we don't know tamil and none of the officers understand English/hindi properly. Somehow a communication happened and I had to show them the account balance online as I didn't have that much cash with me. Finally, the officer agreed to leave us with a cost of Rs 500 and 4 beer cans.\nWe noticed at the same time, 4 college students from chennai were also got caught with a bag full of Liquors. The officer was very casual to them and also denied money from them even though they offered him 200 rupees. They may be from families where the indian law does not get applied easily. I understand that.\nWe can't speak tamil or pondi language.. Is this what you are angry on us? Is this what you discriminate us? Don't you ruin the future of your own students in the name of partiality??\r\n                  ", 
    "\r\n                    Dear Sir,\nThis is not the first time I am facing this issue with Rohit Gas Agency. I tried to bring it to the notice of Indane. Its of no use. Rohit Gas Agency provides worst service. We do not have option. To Deliver the Cylinder, the Delivery boy demands Rs 50 everytime. This is a common issue. If not paid he shouts badly on road and moves out. Rohit Gas Agency is always unreachable. These bugs working in the Gas Agency are eating up the money paid by Gas Subscribers. \nMany a times, the cylinder is not delivered to home. We are forced to collect the Cylinder paying additional bribe of Rs 50 near Godown. If not paid, we need to lift the cylinder and carry the same back till the car parking and drive back home. \nThe Gas Delivery - Rohit Gas Agency is unfit to manage the delivery business. Please look into the complaints and reviews on google atleast. \nRegards\nPrashanth .P\r\n                  ", 
    "\r\n                    I paid bribe today to a police officer who came for passport verification of my mother. Even after providing all supporting documents and required information, officer asked to pay 500Rs for Chai Pani. When I asked to reduce the amount, officer said that it is decided by higher officials of police. \nI feel very bad after paying, this practice is so common in UP. Please take necessary actions against this to prevent civilians from such corrupt people. \nOfficer Name - Indrapal Singh\nThana - New Agra Police Station\nDate - 6th Jan 2020\nPlace - Agra\r\n                  ", 
    "\r\n                    I have asked to pay bribe to avoid huge penalty for putting tent sheet on car windows. Police asked me to pay 1100 rs fine or pay bribe instead of that.  Since I don't had that much money and I was in urgency, I paid bribe to escape from the situation. This was happened at corporation circle church opposite to church at 12 30 PM. \r\n                  ", 
    "\r\n                    Help desk officer prashant who are trapping people to make work done by giving bribes to higher officials at malakpet rto malakpet Hyderabad \r\n                  ", 
    "\r\n                    Get free shipping when you buy the Revolution the great american electric cigarette machine, within the continental US from https://hardworkingproducts.com/revolution-electric-cigarette-machine-made-in-america and also you will get this machine at best market price in USA.\r\n                  ", 
    "\r\n                    I Would like to Inform you that a lot of corruption is going on in the DC Office Bangalore Urban  Dept. I am not paid bribe directly there is lot more agents have to collect the money and some one has do the deel not direct deel with D C Officer. Brib agents collecting the money and send it to direct DC officer house. The Officer have a one more home office in Kumarakrupa road bangalore. the deeling files as going their for officer signature. One agent is doing his job in that office his name called Mahendre Kumar (Shift car No.KA 04 MK 282) Please do the action for this. Govt officers also been included in this deels and they get commission also.\nNames Sadanada Swamy , Basavaraju, G N Shivamurthy.  \r\n                  "))

【问题讨论】:

data.frame(col = unlist(temp)) ? 是的,完成了这项工作。不幸的是,现在 col 是一个因素,但之前的所有条目都是字符。是否可以保留字符类? 【参考方案1】:

您可以将unlisttibble 一起使用

df_tib <- tibble::tibble(col = unlist(bribe.test))

data.frame

df1 <- data.frame(col = unlist(bribe.test), stringsAsFactors = FALSE)

【讨论】:

以上是关于将大列表转换为一列包含所有元素的小标题[重复]的主要内容,如果未能解决你的问题,请参考以下文章

比较列表haskell中的所有元素[重复]

如何测试字符串包含列表中的元素并通过 Pandas 将目标元素分配给另一列

如何使用matlab将文本转换为数值型数据?

检查列表是不是包含与某些东西不同的元素[重复]

如何复制数组中不同次数的元素?

将rdd行转换为一列