Sorry in advance if this seems dumb, still learning R and still learning about classes.
I've created a function that spits back 3 values in list format.
I'm trying to "separate" these values and insert them into a dataframe for use down the line. I want the dataframe to look something like this:
# | pyro1 | pyro2 | pyro3 |
# baseline0 | | | |
# drop time | | | |
# drop temp | | | |
# exo time | | | |
# baseline1 | | | |
# max temp | | | |
# baseline2 | | | |
Basically after calling lapply on my function I'm left with a dataframe that looks like this:
test <- data.frame(c(list(10,1025,1000),list(15,1015,1001),list(9,1019,1029)))
Wherein I have three lists, with 3 values each. I need all the first values from each of the lists to go into a specific row of the above template dataframe I made above.
For example:
# | pyro1 | pyro2 | pyro3 |
# baseline0 | 1025 | 1015 | 1019 |
# drop time | 10 | 15 | 9 |
# drop temp | 1000 | 1001 | 1029 |
# exo time | | | |
# baseline1 | | | |
# max temp | | | |
# baseline2 | | | |
I've tried using rbind, thinking that would work for some reason, but that doesn't work, instead giving something like this:
# | pyro1 | pyro2 | pyro3 |
# baseline0 |list(10.5, 1025, 1023.5) |list(16, 1042, 1036)|list(14.5, 1042, 1038)|
# drop time | | | |
# drop temp | | | |
# exo time | | | |
# baseline1 | | | |
# max temp | | | |
# baseline2 | | | |
Sorry I don't have such a clear working example, if you need more information please let me know, but I think my problem is somewhat basic (sadly).
Also I may be going about the problem in an 'incorrect' way, will gladly accept any suggestions on a different approach.
Thanks
edit1
After playing around with unlist I've put together some ugly code that gives me the formatting I'm looking for, however I think it might be a very roundabout way of doing things.
testt <- data.frame(c(list(10,1025,1000),list(15,1015,1001),list(9,1019,1029)))
xxx<-data.frame(unlist(testt))
xx1 <- cbind(xxx[1,1],xxx[4,1],xxx[7,1])
xx2 <- cbind(xxx[2,1],xxx[5,1],xxx[8,1])
xx3 <- cbind(xxx[3,1],xxx[6,1],xxx[9,1])
xx4 <- rbind(xx1,xx2,xx3)
xx4
str(test).testis not what you think it is. Please provide an example of your actual input.dputis handy for that.dput(test) structure(list(list(10.5, 1025, 1023.5), list(16, 1042, 1036), list(14.5, 1042, 1038)), .Dim = c(1L, 3L), .Dimnames = list( NULL, c("pyro1", "pyro2", "pyro3")))I think it's different than my example actually