1

I have a dataframe called data which contains 5 columns and approximately 181 rows.

I'm trying to run some algorithm on this dataframe, but I have to do some pre-processing beforehand and normalize the columns to have zero and 1. I am using R and the problem that i have columns whit not numeric data like this:

Name       ZwaveType ProprietesName Value                Date
Switcher19         0              2     1 2014-03-01 06:45:00
Switcher5          0              2     1 2014-03-01 07:00:00
Switcher15         0              2     1 2014-03-01 07:15:00
Switcher4          0              2     1 2014-03-01 07:14:30
Switcher15         0              2     0 2014-03-01 07:25:00
Switcher19         0              2     0 2014-03-01 07:45:00

I'd like to ask how can I achieve normalization with R for this case?

David Arenburg
  • 91,361
  • 17
  • 137
  • 196
user3603831
  • 87
  • 1
  • 6
  • 1
    By normalize, what do you mean? How do you want to normalize your data? – RHelp May 19 '14 at 11:29
  • 2
    Why would you normalise text and data fields, `ProprietesName`, `Name`? – zx8754 May 19 '14 at 12:25
  • 2
    I want to generate new column to normalize data according to Column Value and Dtae to separate data whitch have Value 1 and those having Value 0 – user3603831 May 19 '14 at 13:11

1 Answers1

1

Probably something like

col.classes <- sapply(mydata,class)
num.cols <- (col.classes=="numeric")
mydata[,num.cols] <- scale(mydata[,num.cols])
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • 2
    how can I use this function sapply? and what do you mean by 'class' is it the package class? – user3603831 May 19 '14 at 13:15
  • 2
    This is intended to be a complete, literal answer: it assumes `mydata` is your data set. `class` is a function in base R -- see `?class`. – Ben Bolker May 19 '14 at 13:22
  • 1
    I think I may have misunderstood your question. – Ben Bolker May 19 '14 at 13:27
  • 1
    My question was about how to use this function and my data is not numeric , Ihave used already the function normalize : normalize(dataset, byrow=TRUE) and Ihave this error Erreur dans colMeans(x, na.rm = TRUE) : 'x' doit être numérique – user3603831 May 19 '14 at 13:32
  • 2
    I thought of an idea in order to normalize the data from my dataframe. In fact I can overlook the Name column and replace it with a column ID (this is already numeric) so the only non-numeric column that I still have is Date, so I think about browsing my dataframe and I'll generate a new column for each date. as I associate a value, and for the similar dates I will associate the same value, but I don't know until now if it's possible to do this business with R ?? – user3603831 May 19 '14 at 15:20