Dear all, I''d like to ask help on R code to get the same results as the following Splus code:>indata<-importData("/home/data_new.csv")>indata[1:5,4][1] 0930 1601 1006 1032 1020 I tried the following R code:> indata<-read.csv("/home/data_new.csv")> indata[1:5,4][1] 930 1601 1006 1032 1020 I''d like the first one to be 0930, too. Thanks in advance, Betty [[alternative HTML version deleted]]
Superficially, one answer is
indata <- read.csv("/home/data_new.csv",
colClasses="character")
but I'm not sure that's what you want...
-Ista
On Mon, Nov 2, 2009 at 4:09 PM, Fang (Betty) Yang <fang.yang at
ualberta.ca> wrote:> Dear all,
>
>
>
> I'd like to ask help on R code to get the same results as the following
> Splus code:
>
>
>
>
>
>>indata<-importData("/home/data_new.csv")
>
>
>
>>indata[1:5,4]
>
> [1] 0930 1601 1006 1032 1020
>
>
>
> I tried the following R code:
>
>
>
>> indata<-read.csv("/home/data_new.csv")
>
>> indata[1:5,4]
>
> [1] ?930 1601 1006 1032 1020
>
>
>
> I'd like the first one to be 0930, too.
>
>
>
> Thanks in advance,
>
>
>
>
>
> Betty
>
>
>
>
>
>
>
>
>
>
> ? ? ? ?[[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.
>
--
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org
On Nov 2, 2009, at 4:09 PM, Fang (Betty) Yang wrote:> Dear all, > > I'd like to ask help on R code to get the same results as the > following > Splus code: > >> indata<-importData("/home/data_new.csv") > >> indata[1:5,4] > > [1] 0930 1601 1006 1032 1020 > > I tried the following R code: > >> indata<-read.csv("/home/data_new.csv")Do you get what you desire with setting as.is=TRUE? indata<-read.csv("/home/data_new.csv", as.is=TRUE ) Also see the colClasses arguments in read.xxx functions.>> indata[1:5,4] > > [1] 930 1601 1006 1032 1020 > > I'd like the first one to be 0930, too. >So you want the strings (aka "character" vectors) to stay strings. -- David Winsemius, MD Heritage Laboratories West Hartford, CT
I use indata = read.csv(file.choose(),header=TRUE) of course you can specify your file. Joe King 206-913-2912 jp at joepking.com "Never throughout history has a man who lived a life of ease left a name worth remembering." --Theodore Roosevelt -----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Fang (Betty) Yang Sent: Monday, November 02, 2009 1:10 PM To: r-help at r-project.org Subject: [R] problems with read.csv Dear all, I'd like to ask help on R code to get the same results as the following Splus code:>indata<-importData("/home/data_new.csv")>indata[1:5,4][1] 0930 1601 1006 1032 1020 I tried the following R code:> indata<-read.csv("/home/data_new.csv")> indata[1:5,4][1] 930 1601 1006 1032 1020 I'd like the first one to be 0930, too. Thanks in advance, Betty [[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.