-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
  • 51,962
  • 152
  • 427
  • 752

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
  • 18,231
  • 5
  • 36
  • 45