[R] split character line into rows

arun smartpink111 at yahoo.com
Mon Dec 17 16:29:34 CET 2012


Hi,

It would be helpful if you dput() the data.
If I read your data like this:
dat1<-read.table(text="
 2010.12.26 00:00:52    688,88 11,69    43,00
  11,69    43,00
   11,69    43,00
   11,69    43,00
   11,69    43,00
 2010.12.26 00:01:52    696,19    11,69    43,00
",sep="",header=FALSE,fill=TRUE,dec=",",stringsAsFactors=FALSE)


 dat2<-na.omit(dat1)
dat2
#          V1       V2     V3    V4 V5
#1 2010.12.26 00:00:52 688.88 11.69 43
#6 2010.12.26 00:01:52 696.19 11.69 43


#or
dat1[complete.cases(dat1),]

A.K.



----- Original Message -----
From: Simonas Kecorius <simolas2008 at gmail.com>
To: r-help at r-project.org
Cc: 
Sent: Monday, December 17, 2012 7:04 AM
Subject: [R] split character line into rows

Hey R users,

suppose we have data:

[1] 2010.12.26 00:00:52    688,88          11,69     43,00
  [2] 11,69     43,00
  [3] 11,69     43,00
  [4] 11,69     43,00
  [5] 11,69     43,00
  [6] 11,69     43,00
  [7] 11,69     43,00
  [8] 11,69     43,00
  [9] 11,69     43,00
[10] 11,69     43,00
[11] 11,69     43,00
[12] 11,69     43,00
[13] 11,69     43,00
[14] 11,69     43,00
[15] 11,69     43,00
[16] 11,69     43,00
[17] 11,69     43,00
[18] 11,69     43,00
[19] 11,69     43,00
[20] 11,69     43,00
[21] 11,69     43,00
[22] 11,69     43,00
[23] 11,69     43,00
[24] 11,69     43,00
[25] 11,69     43,00
[26] 11,69     43,00
[27] 11,69     43,00
[28] 11,69     43,00
[29] 11,69     43,00
[30] 11,69     43,00
[31] 11,69     43,00
[32] 11,69     43,00
[33] 11,69     43,00
[34] 11,69     43,00
[35] 11,69     43,00
[36] 11,69     43,00
[37] 11,69     43,00
[38] 11,69     43,00
[39] 11,69     43,00
[40] 11,69     43,00
[41] 11,69     43,00
[42] 11,69     43,00
[43] 11,69     43,00
[44] 11,69     43,00
[45] 11,69     43,00
[46] 11,69     43,00
[47] 11,69     43,00
[48] 11,69     43,00
[49] 11,69     43,00
[50] 11,69     43,00
[51] 11,69     43,00
[52] 11,69     43,00
[53] 11,69     43,00
[54] 11,69     43,00
[55] 11,69     43,00
[56] 11,69     43,00
[57] 11,69     43,00
[58] 11,69     43,00
[59] 11,69     43,00
[60] 11,69     43,00
[61] 2010.12.26 00:01:52    696,19          11,69     43,00
[62] 11,69     43,00
[63] 11,69     43,00
[64] 11,69     43,00
[65] 11,69     43,00
[66] 11,69     43,00
..................................... etc.

Is there a way to split data into date column, V2, V3 and V4 columns and
erase those lines without date, so that data would look like that:

date                             V2       V3       V4
2010.12.26 00:01:52     555     11.67     44
2010.12.26 00:02:52     566     11.67     44

etc.

Thanks a lot!


-- 
Simonas Kecorius
**

    [[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.





More information about the R-help mailing list