Do you mean that you have
One data frame, and it has a bunch of variables within it named P1, P2,
P3...
or
A bunch of data frames names P1, P2, P3...
?
I'll assume it's the latter. Here is one way:
dfnms < c('P1', 'P2', 'P3')
for (nm in dfnms) {
tmp <- get(nm)
rownames(tmp) <- tmp[[
Hi Ruiyang,
In this case you don't want the "get", just the strings produced by "paste":
mydf<-data.frame(col1=LETTERS[1:10],col2=1:10)
rownames(mydf)<-paste("P",mydf$col1,sep="")
Jim
On Thu, Nov 16, 2017 at 9:22 AM, 刘瑞阳 wrote:
> Hi,
>
> Thanks for your reply.
>
> I just came up with another qu
Hi,
Thanks for your reply.
I just came up with another question about a similar but different thing:
Say I have a bunch of data.frame variables named P1,P2,P3… I want to assign
them row names according to symbols in the first column, and I want to do this
using a for loop. How could I accompli
Hi Ruiyang,
I think you want "get":
For (index in seq(1,16)){
plot(x=(a given set of value),y=get(paste(“PC”,as.character(index),sep=“”)))
}
On Wed, Nov 15, 2017 at 7:43 AM, 刘瑞阳 wrote:
> Hi,
> Suppose that I want to do a series of plots with the y value for each plot as
> PC1, PC2, PC3… How cou
Hi,
You can also try this:
a <- "1,2"
as.numeric(c(gsub("(.*)\\,(.*)","\\1",a), gsub("(.*)\\,(.*)","\\2",a)))
#[1] 1 2
- Original Message -
From: BenM
To: r-help@r-project.org
Cc:
Sent: Thursday, October 18, 2012 10:17 AM
Subj
Depending on what exactly you are trying to accomplish:
> as.numeric(unlist(strsplit(a, ",")))
[1] 1 2
> read.csv(textConnection(a), header=FALSE)
V1 V2
1 1 2
Sarah
On Thu, Oct 18, 2012 at 9:08 AM, BenM wrote:
> Hi All,
> Thanks in advance for your help. I'm trying to convert a strin
Thank you very much. That appears to be what I wanted.
--
View this message in context:
http://r.789695.n4.nabble.com/converting-a-string-to-an-integer-vector-tp4646610p4646624.html
Sent from the R help mailing list archive at Nabble.com.
__
R-help@
Hello,
Try this, It'll maybe help you:
a <- "1,2"
b <- strsplit(a,",") #split your data according to ","
b <- unlist(b) # it creates a list, so we unlist the result to obtain a
vector like c(1,2)
--
View this message in context:
http://r.789695.n4.nabble.com/converting-a-string-to-an-in
Gotta love R.
Thanks to Bill Dunlap, Peter Langfelder and Jim Holtman for no less than 3 different
solutions.
JN
On 12-03-01 04:25 PM, Peter Langfelder wrote:
pstr<-c("b1=200", "b2=50", "b3=0.3")
split = sapply(strsplit(pstr, split = "="), I);
pnum = as.numeric(split[2, ]);
names(pnum)
On Thu, Mar 01, 2012 at 03:28:31PM -0500, John C Nash wrote:
> Not paying close attention to detail, I entered the equivalent of
>
> pstr<-c("b1=200", "b2=50", "b3=0.3")
>
> when what I wanted was
>
> pnum<-c(b1=200, b2=50, b3=0.3)
>
> There was a list thread in 2010 that shows how to deal with
On Thu, Mar 1, 2012 at 12:28 PM, John C Nash wrote:
> Not paying close attention to detail, I entered the equivalent of
>
> pstr<-c("b1=200", "b2=50", "b3=0.3")
>
> when what I wanted was
>
> pnum<-c(b1=200, b2=50, b3=0.3)
>
> There was a list thread in 2010 that shows how to deal with un-named ve
>
> Of course this is yet another case where Lumley's principle (at
> least I
> think it's his) holds: if you have to use eval(parse(...)) rethink --
> there's a better way.
>
>
> Bert Gunter
> Genentech Nonclinical Statistics
>
>
> -Original
I'm not sure what you mean. You should provide an example (i.e. some code).
Julian
Gang Chen wrote:
> This must be very simple, but I'm stuck. I have a command line in R
> defined as a variable of a string of characters. How can I convert
> the variable so that I can execute it in R?
>
> Re
Cc: [EMAIL PROTECTED]
Subject: Re: [R] Converting a string
Hi -
you can split the string using strsplit().
if your function uses Argument1 as a string, then you're all set. If
that's not the case then you can get() the object.
>myfunc <- function(arg1, arg2) {
+ arg1 <- get
Here is a way of using parse and eval that was previously mentioned.
It works with constants, variable names or expressions:
> myFunc <- function(arg1, arg2) arg1+arg2
>
> x <- 20
> y <- 10
> myFunc(x,y)
[1] 30
>
> tempstr <- 'x,y'
> # split the string
> args <- strsplit(tempstr, ',')
> # parse an
Hi -
you can split the string using strsplit().
if your function uses Argument1 as a string, then you're all set. If
that's not the case then you can get() the object.
>myfunc <- function(arg1, arg2) {
+ arg1 <- get(arg1)
+ arg2 <- get(arg2)
...
}
>args <- "argument1,argument2" # easier with n
Thanks for the help.
One case is like this: With function MyFunc(Argument1,
Argument2, ...) I have the first two arguments defined as one
variable "tempstr", a string of characters, like
tempstr <- "Argument1, Argument2"
The question is how I can feed tempstr into MyFunc to make it
executa
Can you provide an example of your input and what you expect the
output to be. You can always use 'as.numeric'.
On 10/29/07, Gang Chen <[EMAIL PROTECTED]> wrote:
> This must be very simple, but I'm stuck. I have a command line in R
> defined as a variable of a string of characters. How can I conv
Gang Chen wrote:
> This must be very simple, but I'm stuck. I have a command line in R
> defined as a variable of a string of characters. How can I convert
> the variable so that I can execute it in R?
>
>
First parse() it then eval() the result
--
O__ Peter Dalgaard Ø
19 matches
Mail list logo