[R] Substitution of Variables
(Ted Harding)
ted.harding at nessie.mcc.ac.uk
Tue Jul 3 01:32:43 CEST 2007
On 02-Jul-07 23:01:07, Judith Flores wrote:
> Hi,
> I need to run a script under the variable (that
> comes from a csv file) that is assigned to another
> variable. This is very a simplified version of what I
> want to do:
>
> data<-read.csv('name.csv')
> names(data)<-("VA","VB","VC")
>
> v<-VA
>
> mn(v)
>
> Thank you in advance,
> Judith
read.csv() makes 'data' into a dataframe. This is essentially
a list with named components. So VA is not yet available as
a variable in your program. The data for the variable you want
to call "VA" is stored as the component 'data$VA' of 'data'.
The names "VA", "VB", "VC" are the names you have given to
the *components* of 'data'; you have not created separate
variables with these names.
So you can assign the data for VA directly to 'v' with:
v<-data$VA
or (if you think you will need it later) create a variable VA
using
VA<-data$VA
and, if you want a variable called 'v' as well, then:
v<-VA
Hoping this helps,
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <ted.harding at nessie.mcc.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 03-Jul-07 Time: 00:32:40
------------------------------ XFMail ------------------------------
More information about the R-help
mailing list