English 中文(简体)
• 如何将数据框架各栏分为R中的适当清单
原标题:how to split a dataframe s columns into seperate lists in R
  • 时间:2023-12-23 02:24:00
  •  标签:
  • r
  • purrr

我想分立一个数据框架,以便每个栏目是自己的清单。

因此,如果我们采用记号数据集,它将编制一份清单,列出结果模拟,使之与以下代码相仿(无论我如何人工这样做)。

理想的做法是寻找使用<代码>基准的方法:split()或purrr:map()通过数据框架,然后在每一名列中垂直分。

# desired outcome

list(
iris$Sepal.Length
,iris$Sepal.Width
,iris$Petal.Length
,iris$Petal.Width
,iris$Species
)
最佳回答

数据. 范围已经是一个包含这一结构的清单。 唯一的区别可能是各栏在数据中点名。 框架和分级、分级、称等。 Ronak Shah提供了第一份可能最有效的解决办法,因为as.list将把“阶级”和“身份”特性和内容从现有清单中删除,但是由于“姓名”的特性不会被删除,它不会完全达到你规定的目标。 你们还需要:

unname(as.list(head(iris)))   # working with the first six rows to preserve space
#------------------------------
[[1]]
[1] 5.1 4.9 4.7 4.6 5.0 5.4

[[2]]
[1] 3.5 3.0 3.2 3.1 3.6 3.9

[[3]]
[1] 1.4 1.4 1.3 1.5 1.4 1.7

[[4]]
[1] 0.2 0.2 0.2 0.2 0.2 0.4

[[5]]
[1] setosa setosa setosa setosa setosa setosa
Levels: setosa versicolor virginica

我必须祝贺我领导这一努力的原因。 我不能认为抛弃这些属性的任何合理理由。

问题回答

一种简单的办法是使用<条码>。 -

as.list(iris)




相关问题
How to plot fitted model over observed time series

This is a really really simple question to which I seem to be entirely unable to get a solution. I would like to do a scatter plot of an observed time series in R, and over this I want to plot the ...

REvolution for R

since the latest Ubuntu release (karmic koala), I noticed that the internal R package advertises on start-up the REvolution package. It seems to be a library collection for high-performance matrix ...

R - capturing elements of R output into text files

I am trying to run an analysis by invoking R through the command line as follows: R --no-save < SampleProgram.R > SampleProgram.opt For example, consider the simple R program below: mydata =...

R statistical package: wrapping GOFrame objects

I m trying to generate GOFrame objects to generate a gene ontology mapping in R for unsupported organisms (see http://www.bioconductor.org/packages/release/bioc/vignettes/GOstats/inst/doc/...

Changing the order of dodged bars in ggplot2 barplot

I have a dataframe df.all and I m plotting it in a bar plot with ggplot2 using the code below. I d like to make it so that the order of the dodged bars is flipped. That is, so that the bars labeled "...

Strange error when using sparse matrices and glmnet

I m getting a weird error when training a glmnet regression. invalid class "dgCMatrix" object: length(Dimnames[[2]]) must match Dim[2] It only happens occasionally, and perhaps only under larger ...

Generating non-duplicate combination pairs in R

Sorry for the non-descriptive title but I don t know whether there s a word for what I m trying to achieve. Let s assume that I have a list of names of different classes like c( 1 , 2 , 3 , 4 ) ...

Per panel smoothing in ggplot2

I m plotting a group of curves, using facet in ggplot2. I d like to have a smoother applied to plots where there are enough points to smooth, but not on plots with very few points. In particular I d ...

热门标签