[R] one more favor needed

arun smartpink111 at yahoo.com
Thu Mar 27 10:46:36 CET 2014


HI Eliza,
May be this helps:

set.seed(42)
 el <- matrix(sample(1:20,327*365,replace=TRUE),ncol=327)
 colnames(el) <- as.character(interaction(df1,sep="*"))
 el1 <- el[,colnames(el) %in% as.character(interaction(df2,sep="*"))]
 dim(el1)
#[1] 365   5
A.K.



On Tuesday, March 25, 2014 4:15 PM, eliza botto <eliza_botto at hotmail.com> wrote:


[text format is also attached]

Dear Arun,

I need one more favor.This is regading to "df1". What if I have a 

matrix "el" of 327 columns with 365rows each. I want to name them 

with respect to df1. For suppose for first column the name should 

be for first column the name should be 67.75*24.25(the first and 

second column and first row of df1), similarly the name of vector 

2 should be 68.25*24.25 and so on till 327th column of matrix. 

Now there is another matrix, df2 with 2 columns and 5 row. I only 

want to select those columns whose header are similar to what 

written in df2. For example the first row of df2 is 67.75 and 

24.25, so I want to select that column from df1 which has a name 

of 67.75*24.25 and so on till I have a matrix with 5 columns and 

365 rows with columns names as they were in df1.

Thankyou very much in advance

You can suppose "el" by yourself.

dput(df1)<-
structure(list(longitude = c(67.75, 68.25, 69.75, 67.25, 67.75, 
68.25, 68.75, 69.25, 69.75, 70.25, 70.75, 61.75, 62.25, 62.75, 
63.25, 66.75, 67.25, 67.75, 68.25, 68.75, 69.25, 69.75, 70.25, 
70.75, 62.25, 62.75, 63.25, 63.75, 64.25, 64.75, 65.25, 65.75, 
66.25, 66.75, 67.25, 67.75, 68.25, 68.75, 69.25, 69.75, 70.25, 
62.25, 62.75, 63.25, 63.75, 64.25, 64.75, 65.25, 65.75, 66.25, 
66.75, 67.25, 67.75, 68.25, 68.75, 69.25, 69.75, 63.25, 63.75, 
64.25, 64.75, 65.25, 65.75, 66.25, 66.75, 67.25, 67.75, 68.25, 
68.75, 69.25, 63.25, 63.75, 64.25, 64.75, 65.25, 65.75, 66.25, 
66.75, 67.25, 67.75, 68.25, 68.75, 69.25, 69.75, 63.25, 63.75, 
64.25, 64.75, 65.25, 65.75, 66.25, 66.75, 67.25, 67.75, 68.25, 
68.75, 69.25, 69.75, 62.75, 63.25, 63.75, 64.25, 64.75, 65.25, 
65.75, 66.25, 66.75, 67.25, 67.75, 68.25, 68.75, 69.25, 69.75, 
70.25, 70.75, 71.25, 71.75, 62.25, 62.75, 63.25, 63.75, 64.25, 
64.75, 65.25, 65.75, 66.25, 66.75, 67.25, 67.75, 68.25, 68.75, 
69.25, 69.75, 70.25, 70.75, 71.25, 71.75, 72.25, 61.75, 62.25, 
62.75, 63.25, 63.75, 64.25, 64.75, 65.25, 65.75, 66.25, 66.75, 
67.25, 67.75, 68.25, 68.75, 69.25, 69.75, 70.25, 70.75, 71.25, 
71.75, 72.25, 72.75, 61.25, 65.75, 66.25, 66.75, 67.25, 67.75, 
68.25, 68.75, 69.25, 69.75, 70.25, 70.75, 71.25, 71.75, 72.25, 
72.75, 73.25, 66.75, 67.25, 67.75, 68.25, 68.75, 69.25, 69.75, 
70.25, 70.75, 71.25, 71.75, 72.25, 72.75, 73.25, 73.75, 66.75, 
67.25, 67.75, 68.25, 68.75, 69.25, 69.75, 70.25, 70.75, 71.25, 
71.75, 72.25, 72.75, 73.25, 73.75, 74.25, 67.75, 68.25, 68.75, 
69.25, 69.75, 70.25, 70.75, 71.25, 71.75, 72.25, 72.75, 73.25, 
73.75, 74.25, 68.25, 69.25, 69.75, 70.25, 70.75, 71.25, 71.75, 
72.25, 72.75, 73.25, 73.75, 74.25, 69.75, 70.25, 70.75, 71.25, 
71.75, 72.25, 72.75, 73.25, 73.75, 74.25, 74.75, 75.25, 69.75, 
70.25, 70.75, 71.25, 71.75, 72.25, 72.75, 73.25, 73.75, 74.25, 
70.25, 70.75, 71.25, 71.75, 72.25, 72.75, 73.25, 73.75, 70.25, 
70.75, 71.25, 71.75, 72.25, 72.75, 73.25, 73.75, 71.25, 71.75, 
72.25, 72.75, 73.25, 73.75, 71.75, 72.25, 72.75, 73.25, 73.75, 
74.25, 74.75, 75.25, 75.75, 76.25, 76.75, 71.75, 72.25, 72.75, 
73.25, 73.75, 74.25, 74.75, 75.25, 75.75, 76.25, 76.75, 77.25, 
71.75, 72.25, 72.75, 73.25, 73.75, 74.25, 74.75, 75.25, 75.75, 
76.25, 76.75, 71.75, 72.25, 72.75, 73.25, 73.75, 74.25, 74.75, 
75.25, 75.75, 73.25, 73.75, 74.25, 74.75, 75.25), latitude = c

(24.25, 
24.25, 24.25, 24.75, 24.75, 24.75, 24.75, 24.75, 24.75, 24.75, 
24.75, 25.25, 25.25, 25.25, 25.25, 25.25, 25.25, 25.25, 25.25, 
25.25, 25.25, 25.25, 25.25, 25.25, 25.75, 25.75, 25.75, 25.75, 
25.75, 25.75, 25.75, 25.75, 25.75, 25.75, 25.75, 25.75, 25.75, 
25.75, 25.75, 25.75, 25.75, 26.25, 26.25, 26.25, 26.25, 26.25, 
26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 26.25, 
26.25, 26.25, 26.75, 26.75, 26.75, 26.75, 26.75, 26.75, 26.75, 
26.75, 26.75, 26.75, 26.75, 26.75, 26.75, 27.25, 27.25, 27.25, 
27.25, 27.25, 27.25, 27.25, 27.25, 27.25, 27.25, 27.25, 27.25, 
27.25, 27.25, 27.75, 27.75, 27.75, 27.75, 27.75, 27.75, 27.75, 
27.75, 27.75, 27.75, 27.75, 27.75, 27.75, 27.75, 28.25, 28.25, 
28.25, 28.25, 28.25, 28.25, 28.25, 28.25, 28.25, 28.25, 28.25, 
28.25, 28.25, 28.25, 28.25, 28.25, 28.25, 28.25, 28.25, 28.75, 
28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 
28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 28.75, 
28.75, 28.75, 29.25, 29.25, 29.25, 29.25, 29.25, 29.25, 29.25, 
29.25, 29.25, 29.25, 29.25, 29.25, 29.25, 29.25, 29.25, 29.25, 
29.25, 29.25, 29.25, 29.25, 29.25, 29.25, 29.25, 29.75, 29.75, 
29.75, 29.75, 29.75, 29.75, 29.75, 29.75, 29.75, 29.75, 29.75, 
29.75, 29.75, 29.75, 29.75, 29.75, 29.75, 30.25, 30.25, 30.25, 
30.25, 30.25, 30.25, 30.25, 30.25, 30.25, 30.25, 30.25, 30.25, 
30.25, 30.25, 30.25, 30.75, 30.75, 30.75, 30.75, 30.75, 30.75, 
30.75, 30.75, 30.75, 30.75, 30.75, 30.75, 30.75, 30.75, 30.75, 
30.75, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 
31.25, 31.25, 31.25, 31.25, 31.25, 31.25, 31.75, 31.75, 31.75, 
31.75, 31.75, 31.75, 31.75, 31.75, 31.75, 31.75, 31.75, 31.75, 
32.25, 32.25, 32.25, 32.25, 32.25, 32.25, 32.25, 32.25, 32.25, 
32.25, 32.25, 32.25, 32.75, 32.75, 32.75, 32.75, 32.75, 32.75, 
32.75, 32.75, 32.75, 32.75, 33.25, 33.25, 33.25, 33.25, 33.25, 
33.25, 33.25, 33.25, 33.75, 33.75, 33.75, 33.75, 33.75, 33.75, 
33.75, 33.75, 34.25, 34.25, 34.25, 34.25, 34.25, 34.25, 34.75, 
34.75, 34.75, 34.75, 34.75, 34.75, 34.75, 34.75, 34.75, 34.75, 
34.75, 35.25, 35.25, 35.25, 35.25, 35.25, 35.25, 35.25, 35.25, 
35.25, 35.25, 35.25, 35.25, 35.75, 35.75, 35.75, 35.75, 35.75, 
35.75, 35.75, 35.75, 35.75, 35.75, 35.75, 36.25, 36.25, 36.25, 
36.25, 36.25, 36.25, 36.25, 36.25, 36.25, 36.75, 36.75, 36.75, 
36.75, 36.75)), .Names = c("longitude", "latitude"), class = 

"data.frame", row.names = c(54L, 
55L, 58L, 91L, 92L, 93L, 94L, 95L, 96L, 97L, 98L, 118L, 119L, 
120L, 121L, 128L, 129L, 130L, 131L, 132L, 133L, 134L, 135L, 136L, 
157L, 158L, 159L, 160L, 161L, 162L, 163L, 164L, 165L, 166L, 167L, 
168L, 169L, 170L, 171L, 172L, 173L, 195L, 196L, 197L, 198L, 199L, 
200L, 201L, 202L, 203L, 204L, 205L, 206L, 207L, 208L, 209L, 210L, 
235L, 236L, 237L, 238L, 239L, 240L, 241L, 242L, 243L, 244L, 245L, 
246L, 247L, 273L, 274L, 275L, 276L, 277L, 278L, 279L, 280L, 281L, 
282L, 283L, 284L, 285L, 286L, 311L, 312L, 313L, 314L, 315L, 316L, 
317L, 318L, 319L, 320L, 321L, 322L, 323L, 324L, 348L, 349L, 350L, 
351L, 352L, 353L, 354L, 355L, 356L, 357L, 358L, 359L, 360L, 361L, 
362L, 363L, 364L, 365L, 366L, 385L, 386L, 387L, 388L, 389L, 390L, 
391L, 392L, 393L, 394L, 395L, 396L, 397L, 398L, 399L, 400L, 401L, 
402L, 403L, 404L, 405L, 422L, 423L, 424L, 425L, 426L, 427L, 428L, 
429L, 430L, 431L, 432L, 433L, 434L, 435L, 436L, 437L, 438L, 439L, 
440L, 441L, 442L, 443L, 444L, 459L, 468L, 469L, 470L, 471L, 472L, 
473L, 474L, 475L, 476L, 477L, 478L, 479L, 480L, 481L, 482L, 483L, 
508L, 509L, 510L, 511L, 512L, 513L, 514L, 515L, 516L, 517L, 518L, 
519L, 520L, 521L, 522L, 546L, 547L, 548L, 549L, 550L, 551L, 552L, 
553L, 554L, 555L, 556L, 557L, 558L, 559L, 560L, 561L, 586L, 587L, 
588L, 589L, 590L, 591L, 592L, 593L, 594L, 595L, 596L, 597L, 598L, 
599L, 625L, 627L, 628L, 629L, 630L, 631L, 632L, 633L, 634L, 635L, 
636L, 637L, 666L, 667L, 668L, 669L, 670L, 671L, 672L, 673L, 674L, 
675L, 676L, 677L, 704L, 705L, 706L, 707L, 708L, 709L, 710L, 711L, 
712L, 713L, 743L, 744L, 745L, 746L, 747L, 748L, 749L, 750L, 781L, 
782L, 783L, 784L, 785L, 786L, 787L, 788L, 821L, 822L, 823L, 824L, 
825L, 826L, 860L, 861L, 862L, 863L, 864L, 865L, 866L, 867L, 868L, 
869L, 870L, 898L, 899L, 900L, 901L, 902L, 903L, 904L, 905L, 906L, 
907L, 908L, 909L, 936L, 937L, 938L, 939L, 940L, 941L, 942L, 943L, 
944L, 945L, 946L, 974L, 975L, 976L, 977L, 978L, 979L, 980L, 981L, 
982L, 1015L, 1016L, 1017L, 1018L, 1019L))



dput(df2)<-structure(list(longitude = c(67.75, 68.25, 69.75, 

67.25, 67.75
), latitude = c(24.25, 24.25, 24.25, 24.75, 24.75)), .Names = c

("longitude", 
"latitude"), row.names = c(54L, 55L, 58L, 91L, 92L), class = 

"data.frame")



More information about the R-help mailing list