---------- Forwarded message ---------- From: Dong GUO <[email protected]> Date: Sat, Apr 24, 2010 at 4:50 PM Subject: Re: [R] assign value between different type: Double vs Integer To: Sarah Goslee <[email protected]>
Thanks, Sarah. the loop is all right. this is what I just experimented. and when trying to do as.numeric (ggg), and I got the 883 coming out, which basically is the point here. somehow in the process, it transformed the 10354 to 883 as a different a type from Double to Numeric... Dont know how this can happen.. > gdata[1,5] [1] 10354 57290 Levels: -1234 -294 -5 -534 ... 0 1 10 100 1000 10000 100000 ... 9999 > typeof(gdata[1,5]) [1] "integer" > ggg<-gdata[1,5] > ggg [1] 10354 57290 Levels: -1234 -294 -5 -534 ... 0 1 10 100 1000 10000 100000 ... 9999 > integer(ggg) [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [36] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [71] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [106] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [141] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [176] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [211] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [246] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [281] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0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 0 0 0 0 0 0 0 0 [806] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [841] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 [876] 0 0 0 0 0 0 0 0 > ggg[1] [1] 10354 57290 Levels: -1234 -294 -5 -534 ... 0 1 10 100 1000 10000 100000 ... 9999 > as.double(ggg) [1] 883 > as.numeric(ggg) [1] 883 > as.integer(ggg) [1] 883 > typeof(ggg) [1] "integer" > ggg [1] 10354 57290 Levels: -1234 -294 -5 -534 ... 0 1 10 100 1000 10000 100000 ... 9999 > as.numeric(ggg) [1] 883 > ggg[0] factor(0) 57290 Levels: -1234 -294 -5 -534 ... 0 1 10 100 1000 10000 100000 ... 9999 > factor(ggg) [1] 10354 Levels: 10354 > aaa<-factor(ggg) > aaa [1] 10354 Levels: 10354 > typeof(aaa) [1] "integer" > aaa<-as.numeric(factor(ggg)) > aaa [1] 1 > aaa [1] 1 > On Sat, Apr 24, 2010 at 4:45 PM, Sarah Goslee <[email protected]> wrote: > On Sat, Apr 24, 2010 at 9:31 AM, Dong GUO <[email protected]> wrote: >> Dear list, >> >> just to put it in a simple way: >> >> i read.csv from csv file to create a gdata >> >> then, create array gdata34 >> >> however, when making a loop for assigning gdata34[1,m]<-gdata[m,4], >> this is what happen > > So you assigned (m == 4) > > gdata34[1, 4] <- gdata[4, 4] > > >> gdata[1,4] 's real value is 10354, however, the gdata34[1,4] turns to be 883 > > But now you expect > gdata[1,4] == gdata34[1,4] > > If your loop description is correct, > gdata34[1,4] <- gdata[4, 4] > and > gdata34[1,1] <- gdata[1,4] > > Something is wrong either in your description or > your check. I don't think it has anything to do with > storage mode. > > Sarah > >> then i checked the type: gdata[1,4] is integer, while gdata34[1,4] is double. >> >> Can any one give me some help on it???? >> >> Many thanks in advance. >> >> Best regards, >> Dong >> > -- > Sarah Goslee > http://www.functionaldiversity.org > [[alternative HTML version deleted]] ______________________________________________ [email protected] 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.

