-3

This dataframe code :

f <- function (l) {
    l
}

data.frame(lapply(letters[1:2] , f))

which renders :

enter image description here

I'm attempting to transpose the rows to cols so a,b appear as :

X.a. a
X.b. b

I tried :

f <- function (l) {
    l
}

data.frame(t(lapply(letters[1:2] , f)))

But this renders :

enter image description here

Can I use transpose function t() to change how data frame appears ?

Community
  • 1
  • 1
blue-sky
  • 49,326
  • 140
  • 393
  • 691

1 Answers1

2

You want to do this instead:

t(data.frame(lapply(letters[1:2] , f)))

Your code attempts to transpose the output of lapply, which is always a list.

acylam
  • 17,372
  • 5
  • 30
  • 43