I have a problem I cannot get over for a long time. Imagine I have a data frame with 17 colums. 16 of them are craniometric variables of Cervus elaphus and one contains age. The data frame has 83 rows. I want to write a loop which plots the values of each craniometric variable against the age. The names of columns are V1, V2, V3, etc... What I have done till now was writing this: layout(matrix(1:16,4,4)) plot(V1~AGE) plot(V2~AGE) . . . . etc. How to assign a string in the loop so that the program understands it is an object? Thank for your help in advance. Michael
How to assign text string as object?
5 messages · Ing. Michal Kneifl, Ph.D., Henrique Dallazuanna, Michal Kneifl +1 more
Take a look at 'matplot'. If you want to loop, try
for (i in 1:16) plot(df[[paste("V", i, sep="")]] ~ df$AGE)
On 3/16/08, Ing. Michal Kneifl, Ph.D. <xkneifl at mendelu.cz> wrote:
I have a problem I cannot get over for a long time. Imagine I have a data frame with 17 colums. 16 of them are craniometric variables of Cervus elaphus and one contains age. The data frame has 83 rows. I want to write a loop which plots the values of each craniometric variable against the age. The names of columns are V1, V2, V3, etc... What I have done till now was writing this: layout(matrix(1:16,4,4)) plot(V1~AGE) plot(V2~AGE) . . . . etc. How to assign a string in the loop so that the program understands it is an object? Thank for your help in advance. Michael
______________________________________________ R-help at 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.
Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
You can try this also:
sapply(DF[-match("AGE", names(DF))], plot, x=DF$AGE)
On 16/03/2008, Ing. Michal Kneifl, Ph.D. <xkneifl at mendelu.cz> wrote:
I have a problem I cannot get over for a long time. Imagine I have a data frame with 17 colums. 16 of them are craniometric variables of Cervus elaphus and one contains age. The data frame has 83 rows. I want to write a loop which plots the values of each craniometric variable against the age. The names of columns are V1, V2, V3, etc... What I have done till now was writing this: layout(matrix(1:16,4,4)) plot(V1~AGE) plot(V2~AGE) . . . . etc. How to assign a string in the loop so that the program understands it is an object? Thank for your help in advance. Michael
______________________________________________ R-help at 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.
-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O
One more question Jim. What if the names of the columns are not a combination of a letter and an integer? Suppose they are just "names" of craniometric characteristics, like "nasal length", "orbital width" etc? Thanks for you reply. Michael ----- Original Message ----- From: "jim holtman" <jholtman at gmail.com> To: "Ing. Michal Kneifl, Ph.D." <xkneifl at mendelu.cz> Cc: <r-help at stat.math.ethz.ch> Sent: Sunday, March 16, 2008 11:44 PM Subject: Re: [R] How to assign text string as object?
Take a look at 'matplot'. If you want to loop, try
for (i in 1:16) plot(df[[paste("V", i, sep="")]] ~ df$AGE)
On 3/16/08, Ing. Michal Kneifl, Ph.D. <xkneifl at mendelu.cz> wrote:
I have a problem I cannot get over for a long time. Imagine I have a data frame with 17 colums. 16 of them are craniometric variables of Cervus elaphus and one contains age. The data frame has 83 rows. I want to write a loop which plots the values of each craniometric variable against the age. The names of columns are V1, V2, V3, etc... What I have done till now was writing this: layout(matrix(1:16,4,4)) plot(V1~AGE) plot(V2~AGE) . . . . etc. How to assign a string in the loop so that the program understands it is an object? Thank for your help in advance. Michael
______________________________________________ R-help at 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.
-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
I think one of the other solutions suggested a way of doing it if
"AGE" was one of the columns and you wanted to plot against all the
others. It would probably be done in this fashion:
for (i in names(df)[!(names(df) %in% "AGE")]){
plot(df$AGE, df[[i]], main=i, type='l')
}
On 3/17/08, Michal Kneifl <xkneifl at mendelu.cz> wrote:
One more question Jim. What if the names of the columns are not a combination of a letter and an integer? Suppose they are just "names" of craniometric characteristics, like "nasal length", "orbital width" etc? Thanks for you reply. Michael ----- Original Message ----- From: "jim holtman" <jholtman at gmail.com> To: "Ing. Michal Kneifl, Ph.D." <xkneifl at mendelu.cz> Cc: <r-help at stat.math.ethz.ch> Sent: Sunday, March 16, 2008 11:44 PM Subject: Re: [R] How to assign text string as object?
Take a look at 'matplot'. If you want to loop, try
for (i in 1:16) plot(df[[paste("V", i, sep="")]] ~ df$AGE)
On 3/16/08, Ing. Michal Kneifl, Ph.D. <xkneifl at mendelu.cz> wrote:
I have a problem I cannot get over for a long time. Imagine I have a data frame with 17 colums. 16 of them are craniometric variables of Cervus elaphus and one contains age. The data frame has 83 rows. I want to write a loop which plots the values of each craniometric variable against the age. The names of columns are V1, V2, V3, etc... What I have done till now was writing this: layout(matrix(1:16,4,4)) plot(V1~AGE) plot(V2~AGE) . . . . etc. How to assign a string in the loop so that the program understands it is an object? Thank for your help in advance. Michael
______________________________________________ R-help at 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.
-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?
Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve?