in R, i write a function. The output of the function has several columns. how can I have the output as a data frame or matrix, so that i can operate on each column separately? Thanks
Asked
Active
Viewed 34 times
-1
-
please see how to make an [awesome reproducible example for SO](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – hrbrmstr May 12 '14 at 02:49
1 Answers
0
Having said that:
myfunc <- function() {
vec1 <- 1:10
vec2 <- letters[1:10]
return(data.frame(vec1, vec2))
}
myfunc()
## vec1 vec2
## 1 1 a
## 2 2 b
## 3 3 c
## 4 4 d
## 5 5 e
## 6 6 f
## 7 7 g
## 8 8 h
## 9 9 i
## 10 10 j
makes and returns a data frame from two vectors and should be an example you can extend for your purposes.

hrbrmstr
- 77,368
- 11
- 139
- 205