Quantcast
Channel: R data.frame columns into single list - Stack Overflow
Viewing all articles
Browse latest Browse all 4

R data.frame columns into single list

$
0
0

I can't seem to find answer though I'm sure it's already been asked...but I wanted to extract and combine a subset of data.frame columns into a single list without use of any packages. For example:

DF <- data.frame(a = c(1,2,3), b = c(4,5,6), c = c(7,8,9))test <- c(DF[,1], DF[,2], DF[,3]) # Gives what I wanttest <- c(DF[,1:3]) # Doesn't give what I want

So desired output would be a single list of values 1:9. I'd want the subset to be dynamically assigned so I can't do it the way I typed it even though it is giving the output I'd like. The only other way I could think is to have a loop and incrementally add one column at a time e.g. test <- c(test, DF[,i])


Viewing all articles
Browse latest Browse all 4

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>