Hello,
That seems easy.
dat$variable1 <- with(dat, paste(variable1, variable2))
dat$variable2 <- dat$variable3
dat$variable3 <- ""
Then convert variable1 to date/time using as.POSIXct or strptime
See ?strptime.
Hope this helps,
Rui Barradas
Em 11-07-2012 13:30, vioravis escreveu:
Thanks a lot for the guidance. I have another text file with a time stamp and
an empty column as given below:
********************************************************************************************
First line: Skip this line
Second line: skip this line
Third line: skip this line
variable1 Variable2 Variable3 Variable4
Unit1 Unit2 Unit3
11/1/2004 0:00 0.1 0.001
11/1/2004 0:10 0.2 0.002
11/1/2004 0:20 0.3 0.003
11/1/2004 0:30 0.4 0.004
********************************************************************************************
This is space separated text file. When I use the following code:
head <- readLines("testInput.txt", n=4)[4]
dat <- read.table("testInput.txt", skip=5, sep="",fill = TRUE,
stringsAsFactors=FALSE)
names(dat) <- unlist(strsplit(head, " "))
I get the following output:
str(dat)
'data.frame': 4 obs. of 4 variables:
$ variable1: chr "11/1/2004" "11/1/2004" "11/1/2004" "11/1/2004"
$ Variable2: chr "0:00" "0:10" "0:20" "0:30"
$ Variable3: num 0.1 0.2 0.3 0.4
$ Variable4: num 0.001 0.002 0.003 0.004
Variable1's date and time gets split as Variable1 and Variable2 whereas they
should both be part of Variable1.
Also, the empty column is missing from the data frame.
Is there a way to handle these two cases?
Thank you.
Ravi
--
View this message in context:
http://r.789695.n4.nabble.com/Skipping-lines-and-incomplete-rows-tp4635830p4636129.html
Sent from the R help mailing list archive at Nabble.com.
______________________________________________
R-help@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.
______________________________________________
R-help@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.