-1

I have two variables date and referencenumber. Both are extracted from a text string, with the use of a regular expression. They both have the class character.

When I use the cbind.fill function to combine these variables in an already excising dataframe the values are transformed to numeric values, 1 and 1. Instead of "06-07-2016" and "123ABC". I use the cbind.fill function because something only 1 variables is found, and then this variable still must be placed in the dataframe.

When I run the same code on a computer at school, it doesn't transform the values to numeric. So maybe it has something to do with my settings?

Why is this happening?

library(rowr)
dataframevariablen <- as.data.frame(matrix(nrow = 0, ncol = 2))
colnames(dataframevariablen) <- c("date", "refnr")

rulebased(dfgg$Text[i]) #returns the date and refnr as global variable

dataframevariablen[i,] <- cbind.fill(date,refnr, fill = NULL)
Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248
Jelmer
  • 351
  • 1
  • 15

1 Answers1

1

This works for you?

x <- c("6jul2016", "2jan1960", "31mar1960", "30jul1960")
date <- as.Date(x, "%d%b%Y")
refnr="123ABC" #returns the date and refnr as global variable
for (i in 1:length(date))
dataframevariablen[i,] <- data.frame(date[i],refnr,stringsAsFactors = F)
dataframevariablen$date=as.Date(dataframevariablen$date,origin="1970-01-01")
dataframevariablen

        date  refnr
1 2016-07-06 123ABC
2 1960-01-02 123ABC
3 1960-03-31 123ABC
4 1960-07-30 123ABC
Robert
  • 5,038
  • 1
  • 25
  • 43
  • `dataframevariablen[i,] <- data.frame(date[i],refnr,stringsAsFactors = F)` This line did it. Thanks – Jelmer Jul 06 '16 at 17:50