R Basic Question

45 views
Skip to first unread message

novice

unread,
Mar 17, 2014, 7:04:42 AM3/17/14
to r-inla-disc...@googlegroups.com
Hello Guys

I am new in R, so please excuse the really basic questions.
 
Question 1:
I have a dataset called “3.8~irisnf.Rdata”. One of the steps the program does is “ir<-iris[,-5] “. I don’t understand what is happening here? Can someone please explain?
The dataset looks like this :
> str(irisnf)
'data.frame':	150 obs. of  5 variables:
 $ Sepal.l: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...
 $ Sepal.w: num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...
 $ Petal.l: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...
 $ Petal.w: num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...
 $ Variety: Factor w/ 3 levels "1","2","3": 1 1 1 1 1 1 1 1 1 1 ...
 
> dim(irisnf)
[1] 150   5
 
Question 2:
If I perform correlation on my data [cor(nums2)] or try to produce variance matrix [var(nums2)]. The output comes in R console. Is there any way I can make it go directly to excel somehow?
 
 
Question 3:
Also is there anyway I can permanently change the variable name in a data frame.
 
I basically imported my dataset from SAS using "read.ssd" function in library(foreign). However, this package cuts off the variable names and only allows 8 characters! So that means I will have to rename some of my variable names, so they make more sense as to what it is.
 
part (a):
At the moment, I did the following to change the variable names, using library(plyr). First of all, is this the most succint way of doing this?
 
new_acc <- rename(acc_mod,c("NAME_OF_"="weekName",  "ACCIDENT"="AccSev", "YEARMONH"="YrMonHr",
                            "X_1ST_ROA"="1RdCls.N", "ROAD_TYP"="RdType.N", "LOCATION"="LocEast"))
 
 
 
 
part (b):
Secondly, I wanted to do the above, to change the name permanently - but I don't think it worked, because when I do the following, I get:
 
class(LocEast)  # New name of "LOCATION"
class(LOCATION)
R Output:
> class(LocEast)
Error: object 'LocEast' not found
> class(LOCATION)
[1] "numeric"

Håvard Rue

unread,
Mar 17, 2014, 7:07:46 AM3/17/14
to novice, r-inla-disc...@googlegroups.com
Hi,

seems like these questions fits better at a discussion forum for R than
for R-INLA.

Best
H
--
Håvard Rue
Department of Mathematical Sciences
Norwegian University of Science and Technology
N-7491 Trondheim, Norway
Voice: +47-7359-3533 URL : http://www.math.ntnu.no/~hrue
Mobile: +47-9260-0021 Email: havar...@math.ntnu.no

R-INLA: www.r-inla.org

novice

unread,
Mar 17, 2014, 7:13:16 AM3/17/14
to r-inla-disc...@googlegroups.com, novice, hr...@math.ntnu.no
Sorry I am new at this - I was trying to find a discussion forum for R.
Could you point in the right direction as to where I can find it?

Daniel Simpson

unread,
Mar 17, 2014, 7:15:08 AM3/17/14
to novice, r-inla-disc...@googlegroups.com, Håvard Rue


--
You received this message because you are subscribed to the Google Groups "R-inla discussion group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to r-inla-discussion...@googlegroups.com.
To post to this group, send email to r-inla-disc...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages