Loop over string variables in R

后端 未结 4 1069
囚心锁ツ
囚心锁ツ 2021-01-31 20:51

When programming in Stata I often find myself using the loop index in the programming. For example, I\'ll loop over a list of the variables nominalprice and realprice:

4条回答
  •  無奈伤痛
    2021-01-31 21:50

    Using ggplot2 and reshape:

    library(ggplot2)
    library(reshape)
    df <- data.frame(nominalprice=rexp(10), time=1:10)
    df <- transform(df, realprice=nominalprice*runif(10,.9,1.1))
    dfm <- melt(df, id.var=c("time"))
    qplot(time, value, facets=~variable, data=dfm)
    

提交回复
热议问题