[R] Fwd: R basic data manipulation Queries

David Carlson dcarlson at tamu.edu
Tue Mar 18 17:55:05 CET 2014


Not exactly automatic, but if you are using Windows:

1. Open a blank spreadsheet in Excel
2. write.table(cor(nums2), file="clipboard-128", sep="\t") # In
R
3. Paste the clipboard into the spreadsheet

Package xlsx can write Excel format files, but does not put them
directly into Excel.

For the second question, as John said

new_acc <- acc_mod
new_acc <- names(List of names in order)

replaces all of the names. It is fine if you don't have very
many, but rename lets you change just a few.

You need to read some introductory R manuals. Variables stored
within a data.frame are not visible to R without attach(new_acc)
followed by class(LocEast),  or better, class(new_acc$LocEast).

-------------------------------------
David L Carlson
Department of Anthropology
Texas A&M University
College Station, TX 77840-4352

-----Original Message-----
From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-project.org] On Behalf Of John Kane
Sent: Tuesday, March 18, 2014 11:09 AM
To: Pavneet Arora; r-help at r-project.org
Subject: Re: [R] Fwd: R basic data manipulation Queries

In line

John Kane
Kingston ON Canada


> -----Original Message-----
> From: pavneet17 at yahoo.co.uk
> Sent: Tue, 18 Mar 2014 10:10:38 +0000
> To: r-help at r-project.org
> Subject: [R] Fwd: R basic data manipulation Queries
> 
> 
> 
> 
> 
> 
> Sent from Samsung Mobile
> 
> -------- Original message --------
> Subject: R basic data manipulation Queries
> From: Pavneet Arora <pavneet.arora at uk.rsagroup.com>
> To: pavneet17 at yahoo.co.uk
> CC:
> 
> Hello Guys
> 
> I am new in R, so please excuse the really basic questions. I
have tried
> reading numeral tutorials, but I am still stuck.
> Question 1:
> 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?

Not exactly but fairly easily. Have a look at the R-site and go
to the Manuals section.  There is a R Import and Export manual
there.
> 
> Question 2:
> Also is there any way 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"
> 
> Thanks so much!B
> 	[[alternative HTML version deleted]]
> 

I have never used plyr for thhis but just
names(aac.mod)  <-  c("Newname1, "Newname2") and so on for a new
name for each column in the data.frame should do it.

____________________________________________________________
Protect your computer files with professional cloud backup.
Get PCRx Backup and upload unlimited files automatically. 
Learn more at http://backup.pcrx.com/mail

______________________________________________
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