Charles Annis, P.E.
2005-Nov-10 21:46 UTC
[R] converting a character string to a subscripted numeric variable
Dear R-helpers: It seems that I have a mental block. (Some say that it sits atop my shoulders.) For reasons too tedious to retell I have an R object:> input.line[7][1] "-13.24, -11.24, -9.24, -7.24, -5.24, -3.24, -1.24, 0.76, 2.76, 4.76, 6.76, 8.76, 10.76, 12.76, 14.76, 16.76, 18.76, 20.76, 22.76, 24.76, 26.76, 28.76, 30.76, 32.76, 34.76, 36.76, 38.76, 40.76, 42.76, 44.76, ">I would like to convert this into a subscripted variable, Beta, something that should be straightforward if I had *almost* what I have. I'd like to say Beta <- c(-13.24, -11.24, -9.24, -7.24, -5.24, -3.24, -1.24, 0.76, 2.76, 4.76, 6.76, 8.76, 10.76, 12.76, 14.76, 16.76, 18.76, 20.76, 22.76, 24.76, 26.76, 28.76, 30.76, 32.76, 34.76, 36.76, 38.76, 40.76, 42.76, 44.76) but I can't because: input.line[7] is a character string, and it ends in a comma. This cannot be as difficult as I have found it to be. Can anyone help? Copious Thanks. Charles Annis, P.E. Charles.Annis at StatisticalEngineering.com phone: 561-352-9699 eFax:?? 614-455-3265 http://www.StatisticalEngineering.com ??
Sundar Dorai-Raj
2005-Nov-10 22:00 UTC
[R] converting a character string to a subscripted numeric variable
Charles Annis, P.E. wrote:> Dear R-helpers: > > It seems that I have a mental block. (Some say that it sits atop my > shoulders.) > > For reasons too tedious to retell I have an R object: > > >>input.line[7] > > [1] "-13.24, -11.24, -9.24, -7.24, -5.24, -3.24, -1.24, 0.76, 2.76, 4.76, > 6.76, 8.76, 10.76, 12.76, 14.76, 16.76, 18.76, 20.76, 22.76, 24.76, 26.76, > 28.76, 30.76, 32.76, 34.76, 36.76, 38.76, 40.76, 42.76, 44.76, " > > > I would like to convert this into a subscripted variable, Beta, something > that should be straightforward if I had *almost* what I have. > > I'd like to say > > Beta <- c(-13.24, -11.24, -9.24, -7.24, -5.24, -3.24, -1.24, 0.76, 2.76, > 4.76, 6.76, 8.76, 10.76, 12.76, 14.76, 16.76, 18.76, 20.76, 22.76, 24.76, > 26.76, 28.76, 30.76, 32.76, 34.76, 36.76, 38.76, 40.76, 42.76, 44.76) > > but I can't because: > > input.line[7] is a character string, and > > it ends in a comma. > > > This cannot be as difficult as I have found it to be. Can anyone help? > > Copious Thanks.How about: x <- "-13.24, -11.24, " x <- as.numeric(strsplit(x, ",")[[1]]) x[!is.na(x)] --sundar
Apparently Analagous Threads
- [LLVMdev] [llvm-commits] [PATCH] BasicBlock Autovectorization Pass
- Correlation Matrix with a Covariate
- [LLVMdev] [llvm-commits] [PATCH] BasicBlock Autovectorization Pass
- comportamiento de data.table al hacer calculos por grupos
- Accelerated video output with ffmpeg2theora 0.24