[R] Converting CSV file to numeric and calculate ttest

PIKAL Petr petr.pikal at precheza.cz
Fri Sep 4 12:39:39 CEST 2015


Hi

Well, you want us to help you but you do not provide any relevant information

This is a result of first line of your code on my computer

> FCPval <- read.csv("C:/Users/shawin/Desktop/RProgramms/RAdipose/FCPval.csv")
Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  cannot open file 'C:/Users/shawin/Desktop/RProgramms/RAdipose/FCPval.csv': No such file or directory

So nobody knows what is FCPval. If you read it correctly it shall be data frame, from your previous post I presume it is numeric.


> Fc2<-(FCPVal$Fc>=2 | FCPval<=-2);  this will just come out , true false
not extracting the Fc  ,

you does not **extract** anything, you did not ask for extraction.

> FCP<-as.matrix(sapply(FCPval,as.numeric))
> A=as.data.frame(FCP)

Above lines are difficult to grasp. If csv file was numeric why do you want to transfer it to numeric. You shall ***read*** it as numeric at first instance. If the file is not numeric what do you expect as.numeric will do to it. It just put numeric values where they are not appropriate.

Here is an example

> lev
  animals animalYears ind
1    bird           1   2
2     cat           1   2
3     dog           1   2
> as.matrix(sapply(lev,as.numeric))
     animals animalYears ind
[1,]       1           1   2
[2,]       2           1   2
[3,]       3           1   2
>

I will not go deep into source of your this error, it is probably due to properties of your object A

> Fc2<-(A$Fc>=1.3| A$Fc<=-1.3) & A$p=0.05;  // has error when i combine
> condition
>
> Error in (Fc2 <- (A$Fc >= 1.3 | A$Fc <= -1.3) & A$p) = 0.05 :
>   could not find function "<-<-"
>

Here is how you shall do a selection, based on inbuilt iris data set

data(iris)
> dim(iris)
[1] 150   5 # so iris has 150 rows

sel <- (iris$Sepal.Width>4 | iris$Sepal.Width<3) & iris$Petal.Width==1.3
iris[sel,]
    Sepal.Length Sepal.Width Petal.Length Petal.Width    Species
54           5.5         2.3          4.0         1.3 versicolor
56           5.7         2.8          4.5         1.3 versicolor
59           6.6         2.9          4.6         1.3 versicolor
65           5.6         2.9          3.6         1.3 versicolor
72           6.1         2.8          4.0         1.3 versicolor
75           6.4         2.9          4.3         1.3 versicolor
88           6.3         2.3          4.4         1.3 versicolor
90           5.5         2.5          4.0         1.3 versicolor
95           5.6         2.7          4.2         1.3 versicolor
97           5.7         2.9          4.2         1.3 versicolor
98           6.2         2.9          4.3         1.3 versicolor
100          5.7         2.8          4.1         1.3 versicolor

Only 12 are extracted so with proper data everything works. If you want better answer please provide at least result of

str(yourdata)

but preferably the data itself e.g. by

dput(head(FCPval, 20))

Petr

PS. And read R intro as it seems you do not understand R basics.


> -----Original Message-----
> From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of shawin
> Sent: Thursday, September 03, 2015 1:55 PM
> To: r-help at r-project.org
> Subject: Re: [R] Converting CSV file to numeric and calculate ttest
>
> Dear Petr,
>
> This code does not work ?
> For selection values you can use e.g. [
> data(iris)
> sel<-iris$Sepal.Width>4
> iris[sel,] or iris[sel, c(1,3,5)]
>
>
> the data is csv file which is :
> FCPval <-
> read.csv("C:/Users/shawin/Desktop/RProgramms/RAdipose/FCPval.csv")
>
> ;
>
> Fc2<-(FCPVal$Fc>=2 | FCPval<=-2);  this will just come out , true false
> not extracting the Fc  ,
> #######################################################################
> ##############################
> FCP<-as.matrix(sapply(FCPval,as.numeric))
> A=as.data.frame(FCP)
> Fc2<-(A$Fc>=1.3| A$Fc<=-1.3) & A$p=0.05;  // has error when i combine
> condition
>
> Error in (Fc2 <- (A$Fc >= 1.3 | A$Fc <= -1.3) & A$p) = 0.05 :
>   could not find function "<-<-"
>
> write.csv(Fc2,"Fc2.csv",row.names =FALSE )
>
> please need help
>
>
> On Thu, Sep 3, 2015 at 8:56 AM, Shawin Karim <shawinkarim at gmail.com>
> wrote:
>
> > Oh sorry F<2 & F<-2 ,  i need to extract the row value according to
> > the last two column F,P and using condition ,
> >
> > I attached  an test file to see the data
> >
> > On Thu, Sep 3, 2015 at 8:43 AM, PIKAL Petr [via R] <
> > ml-node+s789695n4711787h96 at n4.nabble.com> wrote:
> >
> >> Hi
> >>
> >> what is F?
> >>
> >> F>2 & F<2
> >> this is FALSE for all values of F
> >>
> >> What value you want to extract? All rows corresponding to condition
> >> or just values from specific column.
> >>
> >> For selection values you can use e.g. [
> >> data(iris)
> >> sel<-iris$Sepal.Width>4
> >> iris[sel,] or iris[sel, c(1,3,5)]
> >>
> >> Cheers
> >> Petr
> >>
> >> From: Shawin Karim [mailto:[hidden email]
> >> <http:///user/SendEmail.jtp?type=node&node=4711787&i=0>]
> >> Sent: Thursday, September 03, 2015 9:17 AM
> >> To: PIKAL Petr
> >> Subject: Re: [R] Converting CSV file to numeric and calculate ttest
> >>
> >> I solve it , thanks  but i have an issue please :
> >>
> >>
> >> have a csv file and i would like to extract the value of it with
> >> specific range fof the last column for example; F>2 & F<2 & P=1, and
> >> then write the result to csv file.
> >>
> >> the data is :
> >> x1
> >>
> >> x2
> >>
> >> x3
> >>
> >> x4
> >>
> >> x5
> >>
> >> x6
> >>
> >> 9.488404
> >>
> >> 9.470895
> >>
> >> 9.282434
> >>
> >> 9.366707
> >>
> >> 9.955383
> >>
> >> 9.640816
> >>
> >> 8.63063
> >>
> >> 8.558311
> >>
> >> 8.788391
> >>
> >> 8.576231
> >>
> >> 8.671588
> >>
> >> 8.84298
> >>
> >> 9.354749
> >>
> >> 9.367669
> >>
> >> 9.259953
> >>
> >> 9.421538
> >>
> >> 9.554635
> >>
> >> 9.603745
> >>
> >> 9.944864
> >>
> >> 9.950428
> >>
> >> 10.19102
> >>
> >> 10.07351
> >>
> >> 10.0327
> >>
> >> 10.13079
> >>
> >>
> >> Fc
> >>
> >> p
> >>
> >> 1.037883
> >>
> >> 0.320095
> >>
> >> 1.057708
> >>
> >> 0.060132
> >>
> >> 1.065191
> >>
> >> 0.111192
> >>
> >>
> >>
> >>
> >> I tried the code bellow but , it does not work?
> >>
> >> FCPval <-
> >> read.csv("C:/Users/shawin/Desktop/RProgramms/RAdipose/FCPval.csv")
> >>
> >>  c=as.data.frame(FCPval)
> >>
> >> for (i in 1:rowN){if (C$F[i] >= 2 && C$F[i]<=-2&& C$p[i]<=3){
> >>
> >> dfrmPFC=data.frame(Fc=FC,p=p)}
> >> }
> >>
> >> the error is :
> >>
> >> Error in C$FC : object of type 'closure' is not subsettable.
> >>
> >> can i  extract the value according to the condition
> >>
> >> On Thu, Sep 3, 2015 at 8:14 AM, PIKAL Petr <[hidden email]
> >>
> <http:///user/SendEmail.jtp?type=node&node=4711787&i=1><mailto:[hidde
> >> n email] <http:///user/SendEmail.jtp?type=node&node=4711787&i=2>>>
> >> wrote:
> >> Hi
> >>
> >> p value of what? How do you know that it should be 0.3?
> >>
> >> Your HTML post is mangled and almost unreadable.
> >>
> >> Your code is not reproducible, we do not have AT1.csv
> >>
> >> AT1 shall be numeric so your reading process is wrong and following
> >> conversion to numeric shall be umnnecessary if you read your data
> properly.
> >>
> >> Cheers
> >> Petr
> >>
> >> > -----Original Message-----
> >> > From: R-help [mailto:[hidden email]
> >>
> <http:///user/SendEmail.jtp?type=node&node=4711787&i=3><mailto:[hidde
> >> n email] <http:///user/SendEmail.jtp?type=node&node=4711787&i=4>>]
> On
> >> Behalf Of shawin
> >> > Sent: Wednesday, September 02, 2015 9:08 PM
> >> > To: [hidden email]
> >>
> <http:///user/SendEmail.jtp?type=node&node=4711787&i=5><mailto:[hidde
> >> n email] <http:///user/SendEmail.jtp?type=node&node=4711787&i=6>>
> >> > Subject: Re: [R] Converting CSV file to numeric and calculate
> ttest
> >> >
> >> > p value should be 0.3
> >> >
> >> > On Wed, Sep 2, 2015 at 8:07 PM, Navien [via R] < [hidden email]
> >> > <http:///user/SendEmail.jtp?type=node&node=4711787&i=7>
> >> <mailto:ml-node%[hidden email]
> >> <http:///user/SendEmail.jtp?type=node&node=4711787&i=8>>> wrote:
> >> >
> >> > > I have a csv file i convert it to numeric value , then i apply
> >> > > t-test , but t-test result is not correct: please could you
> guide
> >> > > me. the
> >> > data :
> >> > > ID x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15 1367452_at
> >> > > 9.488404158 9.470895414 9.282433728 9.366707445 9.955383045
> >> > > 9.640816474 9.606262272 9.329651027 9.434541611 9.473922432
> >> > > 9.311412966
> >> > > 9.3154885 9.434977488 9.470895414 9.764258059 1367453_at
> >> > > 8.630629966
> >> > > 8.55831075 8.788391003 8.576231135 8.671587906
> >> > > 8.842979993 8.861958856 8.58330436 8.603596508 8.570129609
> >> > > 8.59798922
> >> > > 8.572686772 8.679751791 8.663950953 8.432875347 1367454_at
> >> > 9.354748885
> >> > > 9.367668838 9.259952558 9.421538213 9.554635162
> >> > > 9.603744578 9.452197983 9.284228877 9.404607878 9.317737979
> >> > > 9.343115301
> >> > > 9.310644266 9.27227486 9.360337823 9.44706281 1367455_at
> >> > > 9.944863964
> >> > > 9.950427516 10.19101759 10.07350804 10.03269879
> >> > > 10.1307908 10.03487287 9.74609383 9.886379007 9.775472567
> >> > > 10.036596
> >> > > 9.544738458 9.699611598 9.911962567 9.625804277
> >> > >           AT1 <-
> >> > > read.csv("C:/Users/shawin/Desktop/RProgramms/RAdipose/AT1.csv",
> >> > >  stringsAsFactors=TRUE)
> >> > >
> >> > >
> >> > > str(AT1)
> >> > > matAT = data.frame(AT1[,-1])
> >> > > str(matAT)
> >> > > write.csv(matAT,"matAT.csv",row.names=FALSE)
> >> > > #convert the csv file to numeric
> >> > > matAT<-as.matrix(sapply(matAT,as.numeric))
> >> > > str(matAT)
> >> > > group<-factor(rep(c("Ob","Ln"),times=c(7,8)))
> >> > > t.test(matAT[1,]~group)
> >> > >
> >> > >
> >> > >
> >> > >
> >> > >
> >> > >
> >> > >
> >> > > ------------------------------
> >> > > If you reply to this email, your message will be added to the
> >> > > discussion
> >> > > below:
> >> > >
> >> > > http://r.789695.n4.nabble.com/Converting-CSV-file-to-numeric-
> and-
> >> > calcu
> >> > > late-ttest-tp4711770.html To start a new topic under R help,
> >> > > email [hidden email]
> >> <http:///user/SendEmail.jtp?type=node&node=4711787&i=9><mailto:ml-
> nod
> >> e%[hidden email]
> >> <http:///user/SendEmail.jtp?type=node&node=4711787&i=10>>
> >> > > To unsubscribe from R, click here
> >> > >
> >> >
> <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=unsub
> >> > scr
> >> > >
> >> >
> ibe_by_code&node=789695&code=c2hhd2lua2FyaW1AZ21haWwuY29tfDc4OTY5NX
> >> > wtM
> >> > > jQ0MzkwMjQ1>
> >> > > .
> >> > > NAML
> >> > >
> >> >
> <http://r.789695.n4.nabble.com/template/NamlServlet.jtp?macro=macro
> >> > _vi
> >> > >
> >> >
> ewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespa
> >> > ces
> >> > > .BasicNamespace-nabble.view.web.template.NabbleNamespace-
> >> > nabble.naml.n
> >> > > amespaces.BasicNamespace-
> nabble.view.web.template.NabbleNamespace
> >> > > -
> >> > nabb
> >> > >
> >> >
> le.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%2
> >> > 1na
> >> > > bble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-
> >> > send_instant_em
> >> > > ail%21nabble%3Aemail.naml>
> >> > >
> >> >
> >> >
> >> >
> >> >
> >> > --
> >> > View this message in context:
> >> > http://r.789695.n4.nabble.com/Converting-
> >> > CSV-file-to-numeric-and-calculate-ttest-tp4711770p4711771.html
> >> > Sent from the R help mailing list archive at Nabble.com.
> >> >       [[alternative HTML version deleted]]
> >> >

________________________________
Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. Delete the contents of this e-mail with all attachments and its copies from your system.
If you are not the intended recipient of this e-mail, you are not authorized to use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by modifications of the e-mail or by delay with transfer of the email.

In case that this e-mail forms part of business dealings:
- the sender reserves the right to end negotiations about entering into a contract in any time, for any reason, and without stating any reasoning.
- if the e-mail contains an offer, the recipient is entitled to immediately accept such offer; The sender of this e-mail (offer) excludes any acceptance of the offer on the part of the recipient containing any amendment or variation.
- the sender insists on that the respective contract is concluded only upon an express mutual agreement on all its aspects.
- the sender of this e-mail informs that he/she is not authorized to enter into any contracts on behalf of the company except for cases in which he/she is expressly authorized to do so in writing, and such authorization or power of attorney is submitted to the recipient or the person represented by the recipient, or the existence of such authorization is known to the recipient of the person represented by the recipient.


More information about the R-help mailing list