[R] grep problem decimal points looping

RCulloch ross.culloch at dur.ac.uk
Tue Aug 10 17:14:19 CEST 2010


Hi David, 

Thanks very much for that reply! I might be a touch out of my comfort zone,
but I can see how the loop script works and where I went wrong, but I'm not
sure if I am asking the correct questions here, or perhaps more accurately
I'm using the wrong command for the task in question - and as you say more
info would be better! So.....

I want to split the data by day to look at the proportion of time an
individual spent in each of the eight behaviours - there are 30 rows (i.e.
individuals).

So I'm going over old code trying to make it better (not that it could be
worse!), especially trying to make it more efficient!

So my old code did this (manually for each day):

##DAY1##
DAY1 <-cbind(scananal$X1.1, scananal$X2.1, scananal$X3.1, scananal$X4.1,
scananal$X5.1, scananal$X6.1, scananal$X7.1, scananal$X8.1)
head(DAY1)

which would give, for example,

head(DAY1)
     [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8]
[1,]   14    0    2    1    2    2    0    3
[2,]   23    0    0    1    0    0    0    0
[3,]    0    0    0    0    0    0    0    0
[4,]    0    0    0    0    0    0    0    0
[5,]    0    0    0    0    0    0    0    0
[6,]    0    0    0    0    0    0    0    0



I'd run the following script to get the proportions then bind that together
with other data



###~~~~DAY1~~~###

## CALC NSCANS PER ID ##
n <- rowSums(DAY1)

## GIVE THE DAY NUMBER TO THE DATAFILE
DAY <- rep(1,30)

## CALC PROPORTION OF TIME IN EACH ACTIVITY ##
scansprop <- as.data.frame(prop.table(DAY1,1))
head(scansprop)

##CALC AS ARC_SINE_TRANSFORMED###
transscan<-asin(scansprop)
head (transscan)
##gives column headings##
names(transscan)

##CHECK IT ALL ADDS TO ONE!! ##
rowSums(scansprop)

##MERGES ALL THE DATA FOR THE DAY
DAY1_SUM <- cbind(n,DAY,DAY1,scansprop,transscan)



Then I would merge each of the days, so this script works, but I know it is
rather a poor effort in R script to say the least!

I'm trying to work through this myself, but hit a hurdle in the first
instance!

Not sure if this is any clearer?

Cheers,

Ross

-- 
View this message in context: http://r.789695.n4.nabble.com/grep-problem-decimal-points-looping-tp2319773p2319941.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list