read

Here is a quick demo to convert data represented in lines to a data.frame in R.

For gathering the data, we will use a sample provided at r - Reshape wide format, to multi-column long format - Stack Overflow.

Demonstration to Convert Lines to a data frame in R

The R code is as follows

> Lines <- "ID   Test Year   Fall Spring Winter
+     1   1   2008    15      16      19
+     1   1   2009    12      13      27
+     1   2   2008    22      22      24
+     1   2   2009    10      14      20
+     2   1   2008    12      13      25
+     2   1   2009    16      14      21
+     2   2   2008    13      11      29
+     2   2   2009    23      20      26
+     3   1   2008    11      12      22
+     3   1   2009    13      11      27
+     3   2   2008    17      12      23
+     3   2   2009    14      9       31"
> d <- read.table(textConnection(Lines), header=TRUE)
> d
   ID Test Year Fall Spring Winter
1   1    1 2008   15     16     19  
2   1    1 2009   12     13     27  
3   1    2 2008   22     22     24  
4   1    2 2009   10     14     20  
5   2    1 2008   12     13     25  
6   2    1 2009   16     14     21  
7   2    2 2008   13     11     29  
8   2    2 2009   23     20     26  
9   3    1 2008   11     12     22  
10  3    1 2009   13     11     27  
11  3    2 2008   17     12     23  
12  3    2 2009   14      9     31  
>
Blog Logo

Santosh

Ghost Lover!


Published

Image

Random Thoughts!

Fast and Mobile Life!

Back to Overview