[R] Basic question -loading data

Jeff Newmiller jdnewmil at dcn.davis.CA.us
Wed Aug 15 09:27:23 CEST 2012


"data" is the name of a base function in R. Functions are objects of type "closure". You can find out more about this function by reading the help. If you create your own object named "data" then your object will "hide" the base function and you won't be able to use it when you want to. Type

?data

You used the read.csv function alright, but you did not assign the function return value to a variable, so it just printed it and threw it away.

Try

dta <- read.csv("document.csv", header = TRUE )
str(dta)
summary(dta)

If you don't know whether some variable name you want to use is already "taken", you can just type the name alone at the R prompt:

data

if it gives a not-found error then you should be safe to use it.  A couple of tempting names you should also avoid are

c (commonly used function for making vectors. Tempting because it comes after "a" and "b")
t (the transpose function for matrices. Tempting for naming time variables.)
df (density of the f distribution. Tempting because data frames are very often used object classes.)
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<jdnewmil at dcn.davis.ca.us>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
--------------------------------------------------------------------------- 
Sent from my phone. Please excuse my brevity.

Dinuk Jayasuriya <Dinuk.Jayasuriya at anu.edu.au> wrote:

>Hi all,
>
>New user here - I include the following command in the prompt
>
>read.csv("document.csv", header = TRUE )
>
>and the output shows up. 
>
>But when I include the following command 
>
>summary(data)
>
>I get the following message "Error in object[[i]] : object of type
>'closure' is not subsettable"
>
>Can someone please advise why R is not reading my data?
>
>Thanks
>
>	[[alternative HTML version deleted]]
>
>______________________________________________
>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.



More information about the R-help mailing list