I want to import some "target values" to normalize elements of a
dataframe.  I'm summarizing the existing totals using
as.matrix(xtabs(~tripid_nu+lineon, data=SurveyData)) and reading a .csv
table of target values.  I can't even get them to list out as similar
data items.  

 

 

My idea is to do something like this, but I don't know how to do it in R

          SurveyData$X1 =  NewTargetX1Sums[Trip,Stop]   /
CurrentX1Sums[Trip,Stop]

                   That is; a different value for X1 for each
[Trip,Stop] combination

   

 

Should I be using as.matrix?  

Why doesn't NewTargetX1Sums "name the rows" when CurrentX1Sums does?  

Why does NewTargetX1Sums have dots in the label spaces?

Do I have the right data organization for my problem?

 

 

 

What I've done:

> SurveyData <- read.spss("C:/Data/R/orange_delivery.sav",
use.value.labels=TRUE, max.value.labels=Inf, to.data.frame=TRUE)

> NewTargetData  <- read.table("C:/Data/R/NewTarget.csv", header=TRUE,
sep=",", na.strings="NA", dec=".")

> 

> CurrentX1Sums <- as.matrix(xtabs(~tripid_nu+lineon, data=SurveyData))


> CurrentX2Sums <- apply(CurrentX1Sums, 1, sum)

> NewTargetX1Sums <- as.matrix(NewTargetData)

> NewTargetX2Sums <- apply(NewTargetX1Sums, 1, sum)

> 

> CurrentX1Sums

         lineon

tripid_nu Warner Center De Soto Pierce College Tampa Reseda Balboa
Woodley Sepulveda Van Nuys Woodman Valley College Laurel Canyon North
Hollywood

  9011880             1       0              2     1      0      2
1         0        0       0              1             0
0

  9011890             0       0              0     0      0      0
1         0        0       0              0             1
0

  9011960             1       1              2     0      1      1
0         1        3       2              1             0
0

  9011970             0       0              0     0      1      0
0         1        6       1              1             1
14

  9012040             1       1              1     3      2      7
1         1        1       0              0             0
0

    {Snip}

 

> NewTargetX1Sums

      tripid_nu Warner.Center De.Soto Pierce.College Tampa Reseda Balboa
Woodley Sepulveda Van.Nuys Woodman Valley.College Laurel.Canyon
North.Hollywood

 [1,]   9011880             5       2              2     2      2      2
2         2        2       2              6             4
1

 [2,]   9011890             1       1              1     1      1      1
2         1        1       1              1             2
1

 [3,]   9011960             2       2              2     1      2      2
1         2        3       2              2             1
1

 [4,]   9011970             1       1              1     1      2      1
1         2        6       2              2             2
24

 [5,]   9012040             2       2              2     3      2      7
2         2        2       1              1             1
1

    {Snip}

 

 

 

 

 

Robert Farley

Metro

1 Gateway Plaza

Mail Stop 99-23-7

Los Angeles, CA 90012-2952

Voice: (213)922-2532

Fax:    (213)922-2868

www.Metro.net 

 

 


        [[alternative HTML version deleted]]

______________________________________________
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.

Reply via email to