-6

enter image description here

how to create a dataframe in R from " Min. 1stQu Median Mean 3rdQu Max. NA's" ?? The Data of "Min. 1stQu Median Mean 3rdQu Max. NA's" is attached in the image.

Min.1stQu. Median Mean3rdQu. Max. NA's
0 25000 45000 66200 82000 615000 328

let the column name be "Income". dataframe is attached!

And if I summarize the dataframe it should look like :

Summary(Income)

Min.1stQu. Median Mean3rdQu. Max. NA's
0 25000 45000 66200 82000 615000 328
Pierre.Vriens
  • 2,117
  • 75
  • 29
  • 42
Hans
  • 1
  • 3
  • `read.table(text = "Min. 1sQu. Median Mean 3rdQu. Max. NA's 0 25000 45000 66200 82000 615000 328", header = T)` – SymbolixAU May 17 '16 at 01:25
  • hey thanks, but that would go to just columns names. I have edited the query if it helps! – Hans May 17 '16 at 01:35
  • It's unclear what you're actually asking (hence the down votes). Have a read through [how to make a great reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – SymbolixAU May 17 '16 at 01:51
  • yes, I believe andI I'll look to the link but I will ask you again this query! How you go about creating a dataframe of a single column from the data ( you can see in the picture) – Hans May 17 '16 at 02:02
  • 1
    `as.data.frame(t(as.matrix(summary(Income))))` – rawr May 17 '16 at 02:03
  • @ZheyuanLi names of what? min median max? no it doesnt – rawr May 17 '16 at 02:05
  • @rawr 'summary(Income)' doesn't exist, rather I have a data! – Hans May 17 '16 at 02:15

1 Answers1

1

One approach is to use the tidy function from the broom package. It is versatile and can organize most R statistical results into a data frame.

library(broom)
set.seed(1)
x <- rnorm(1000)
x[sample(1:length(x), 100)] <- NA
df <- tidy(summary(x))
df
  minimum      q1   median    mean     q3 maximum NA's
1  -3.008 -0.6834 -0.01371 0.00106 0.6978    3.81  100

As you can see, it is a data frame:

class(df)
[1] "data.frame"
Gopala
  • 10,363
  • 7
  • 45
  • 77