Please have a look at the preview of the data in theimage. I would like to create 3 new columns i.e. Start, End, Density and create new row for each record in these 3 columns.
Asked
Active
Viewed 53 times
-5
-
4Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to give a [reproducible example](http://stackoverflow.com/questions/5963269). This will make it much easier for others to help you. – zx8754 Aug 06 '18 at 15:48
-
`data.frame(start = c(...), end = c(...), density = c(...)`? – jyr Aug 06 '18 at 15:49
-
`as.data.frame(data1[["first_paint.histogram.bin"]][1])`? – r2evans Aug 06 '18 at 16:07
-
In your list, does the length of start, end and density match? If so , just do `data.frame(mylist)` – Onyambu Aug 06 '18 at 16:07
-
2Also, please do not post data or code as an image. Why? Please read [Why not upload images of code?](https://meta.stackoverflow.com/q/285551/4752675) – G5W Aug 06 '18 at 16:10
-
@zx8754 Sure, I'm new here. I will frame the questions in a better way next time. Thanks. – Srikar Sud Aug 06 '18 at 18:57
-
@jyr I'm not able to manipulate the data inside this list. – Srikar Sud Aug 06 '18 at 19:00
-
Great, then please post reproducible example `dput(head(mydata))`. And provide expected output. – zx8754 Aug 06 '18 at 19:01
1 Answers
0
In accordance with comments above you can converse list
into the data.frame
as below:
# simulation of data.frame with one row and one cell with histogram
z <- hist(rnorm(1000))
z$start <- z$breaks[-length(z$breaks)]
z$end <- z$breaks[-1]
z[c("mids", "xname", "breaks", "equidist", "counts")] <- NULL
names_z <- names(z)
attributes(z) <- NULL
df <- data.frame(a = 1, b = 2, x = I(list((z))))
# Conversion of list to dataframe
setNames(as.data.frame(unlist(df["x"], recursive = FALSE)), names_z)
Output:
density start end
1 0.012 -3.0 -2.5
2 0.042 -2.5 -2.0
3 0.082 -2.0 -1.5
4 0.182 -1.5 -1.0
5 0.288 -1.0 -0.5
6 0.354 -0.5 0.0
7 0.418 0.0 0.5
8 0.300 0.5 1.0
9 0.172 1.0 1.5
10 0.088 1.5 2.0
11 0.050 2.0 2.5
12 0.012 2.5 3.0

Artem
- 3,304
- 3
- 18
- 41