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 ...
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"