This is my function:
x<-read.table(....., stringsAsFactors=FALSE, header=T);
x;
Timestamp time Barcode
1 11/1/2013 8:25 M01.A
2 11/1/2013 8:25 M01.B
3 11/1/2013 8:43 M02.A
4 11/1/2013 8:43 M02.B
5 11/1/2013 9:03 M03.A
6 11/1/2013 9:03 M03.B
7 11/1/2013 9:18 M04.A
8 11/1/2013 9:18 M04.B
dput(head(x));
structure(list(Timestamp = c("11/1/2013", "11/1/2013", "11/1/2013",
"11/1/2013", "11/1/2013", "11/1/2013"), time = c("8:25", "8:25",
"8:43", "8:43", "9:03", "9:03"), Barcode = c("M01.A", "M01.B",
"M02.A", "M02.B", "M03.A", "M03.B")), .Names = c("Timestamp",
"time", "Barcode"), row.names = c(NA, 6L), class = "data.frame")
target<- x$Timestamp;
t<- strptime(x$Timestamp, format = "%m/%d/%Y");
t;
[1] "2013-11-01" "2013-11-01" "2013-11-01" "2013-11-01" "2013-11-01" "2013-11-01" "2013-11-01" "2013-11-01"
for (i in seq_along(target)){
x$Timestamp[x$Timestamp == target[i]]<- t[i]
};
I am trying to covert a date using strptime, and it works, now I am trying to take this vector of indices and replace this column x$Timestamp. Can anyone tell me what I am doing wrong? I just dont see it.
This is the error I get:
Error in $<-.data.frame
(*tmp*
, "Timestamp", value = list(sec = c(0, :
replacement has 9 rows, data has 78