[R] converting numeric into character strings

2009-05-13 Thread Melissa2k9

Hi,

Im trying to put some numbers into a dataframe , I have a list of numbers
(change points in a time series) like such

[1]  2 11 12 20 21 98 99

but I want R to recognise this as just a character string so it will put it
in one row and column, ideally I want them seperated by commas so I would
have for example

Person  Change points (seconds)
A   2,11,12,20,21,98,99  
B4,5,89
 
etc. Is there any way I can get this

I've tried this:

for example if the command to get the list of numbers was b<-which(a!=s),
then i have tried

as.character(b) but I just end up with 

[1] "2"  "11" "12" "20" "21" "98" "99"

which is not what I want as this is more than one string and is not
seperated by commas, I also tried

paste(b,sep=",") but I end up with the same thing. Sorry it's a bit
confusing to read but any help would be great! 

Melissa
-- 
View this message in context: 
http://www.nabble.com/converting-numeric-into-character-strings-tp23518762p23518762.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] turning list into vector/dataframe

2009-04-10 Thread Melissa2k9

Hi,

I have used this command :

resamples<-lapply(1:1000,function(i) sample(lambs,replace=F))
resamples2<-lapply(resamples,Cusum)

to get a list of 1000 samples of my data. The function Cumsum is defined as
follows:

Cusum<-function(x){
SUM<-cumsum(x)-(1:length(x))*mean(x)
min<-min(cumsum(x)-(1:length(x))*mean(x))
max<-max(cumsum(x)-(1:length(x))*mean(x))
diff<-max-min
ans<-c(min,max,diff)
ans
}


where lambs is a vector of temperatures.

An example of part of my list is:

[[998]]
[1] -5.233176  6.903034 12.136210

[[999]]
[1] -9.296690  1.516233 10.812922

[[1000]]
[1] -1.502066e+01 -4.547474e-13  1.502066e+01

Now I want to convert this list into a dataframe so for example 1000 rows
with col names Min, Max and Diff. My supervisor said I first had to turn
this into a vector but I don't seem to be able to do that!

Any ideas on how to turn this list into a dataframe would be really
appreciated :) Thanks in advance

Melissa
-- 
View this message in context: 
http://www.nabble.com/turning-list-into-vector-dataframe-tp22984623p22984623.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] Sequences

2009-04-07 Thread Melissa2k9

Hi,

I am trying to make a sequence and am  using a for loop for this. I want to
start off with an initial value ie S[0]=0 then use the loop to create other
values. This is what I have so far but I just keep getting error messages.

#To calculate the culmulative sums:

s<-rep(0,207)#as this is the length of the
vector I know I will have
s<-as.vector(s)
s[0]<-0
for (i in 1:length(lambs))# where lambs is a vector of
length 207 consisting of temperature 
values


{
s[i]<-s[i-1]-mean(lambs)
}

I continually get the error message: 

Error in s[i] <- s[i - 1] - mean(lambs) : replacement has length zero


When I merely use s[i]<-i-mean(lambs) it works so there is obviously
something wrong with the s[i-1] but i cant see what. All I want is for each
S[i] to be the previous value for S - the mean!
-- 
View this message in context: 
http://www.nabble.com/Sequences-tp22927714p22927714.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


Re: [R] for loop for extracting linear model info

2009-04-04 Thread Melissa2k9



Uwe Ligges-3 wrote:
> 
> 
> 
> Melissa2k9 wrote:
>> Hi,
>> 
>> I have written a for loop as such:
>> 
>> model<-lm(Normalised~Frame,data=All,subset=((Subject==1)&(Filmclip=="Strand")))
>> summary(model)
>> 
>> ###
>> #To extract just the Adjusted R squared
>> ###
>> 
>> rsq<-summary(model)[[9]]
>> 
>> ###
>> #To extract just the slope
>> ###
>> 
>> slope<-summary(model)[[4]][[2]]
>> 
>> ###
>> #To extract only the p value from the t test for slope
>> ###
>> 
>> pvalue<-summary(model)[[4]][[8]]
>> 
>> 
>> data<-data.frame(slope,pvalue,rsq)
>> 
>> 
>> 
>> ###
>> #To extract this info for all films
>> 
>> 
>> for (i in c(1:8,10:20,22:29))
>> {
>> model_1<-lm(Normalised~Frame,data=All,subset=((Subject==i)&(Filmclip=="Strand")))
>> summary(model_1)
>> slope<-summary(model_1)[[4]][[2]]
>> pvalue<-summary(model_1)[[4]][[8]]
>> rsq<-summary(model_1)[[9]]
>> data2<-data.frame(slope,pvalue,rsq)
>> data2<-rbind(data,data2)
>> }
>> 
>> I want this to run for all i but so far I am only getting two entries in
>> my
>> data frame, one for the first subject, and another.
> 
> 
> You are overwriting the old data2 with a new one that consists of those 
> two in each iteration of the loop ...
> 
> 
> Uwe Ligges
> 
> 
>> Does anyone know where I am going wrong in my code so I can have this
>> data
>> for all subjects 1-8,10-20, and 22-29.
>> 
>> Thanks
> 
> __
> R-help@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.
> 
> 





Hey,

Thanks, but do you have any advice on how to stop overwriting the old data2
and just keep adding a new row for each different subject?

Thanks :)
-- 
View this message in context: 
http://www.nabble.com/for-loop-for-extracting-linear-model-info-tp22869348p22870149.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] for loop for extracting linear model info

2009-04-03 Thread Melissa2k9

Hi,

I have written a for loop as such:

model<-lm(Normalised~Frame,data=All,subset=((Subject==1)&(Filmclip=="Strand")))
summary(model)

###
#To extract just the Adjusted R squared
###

rsq<-summary(model)[[9]]

###
#To extract just the slope
###

slope<-summary(model)[[4]][[2]]

###
#To extract only the p value from the t test for slope
###

pvalue<-summary(model)[[4]][[8]]


data<-data.frame(slope,pvalue,rsq)



###
#To extract this info for all films


for (i in c(1:8,10:20,22:29))
{
model_1<-lm(Normalised~Frame,data=All,subset=((Subject==i)&(Filmclip=="Strand")))
summary(model_1)
slope<-summary(model_1)[[4]][[2]]
pvalue<-summary(model_1)[[4]][[8]]
rsq<-summary(model_1)[[9]]
data2<-data.frame(slope,pvalue,rsq)
data2<-rbind(data,data2)
}

I want this to run for all i but so far I am only getting two entries in my
data frame, one for the first subject, and another.

Does anyone know where I am going wrong in my code so I can have this data
for all subjects 1-8,10-20, and 22-29.

Thanks
-- 
View this message in context: 
http://www.nabble.com/for-loop-for-extracting-linear-model-info-tp22869348p22869348.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] Linear model, finding the slope

2009-04-03 Thread Melissa2k9

Hi

for some data I working on I am merely plotting time against temperature for
a variable named filmclip. So for example, I have volunteers who watched
various film clips and have used infared camera to monitor the temperature
on their face at every second of the clip. 

The variable names I have used are Normalised ( for the temperature) and
Frame (for the time in seconds).

So I have fitted a linear model

model<-lm(Normalised~Frame,data=All,subset=((Subject==1)&(Filmclip=="Whatever")

and coef(model)

gives me an intercept value and a value for the slope. Now what I want to do
is find out if the slope is significant or not. So far I just have values
such as 0.02211 for example and have no idea if this is to be interpreted as
significant or not. 

Sorry if I haven't been clear but any advice on how to find out what values
are significant would be greatly appreciated.
-- 
View this message in context: 
http://www.nabble.com/Linear-model%2C-finding-the-slope-tp22865254p22865254.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.


[R] the by function

2009-03-26 Thread Melissa2k9

Hey,

I have a dataframe with subjects who have watched films. The variables of
interest are Pixel number and Temperature on the face. For each subject
there are 8 films, for each film for each subject I need to measure the mean
number of pixels then merge this vector with the data frame. I have 

mean.pixels<-as.data.frame(by(Final[,5],Final[,1:2],mean)[1:13,])

where column 5 is the pixels variable and 1 and 2 are subject and film
number respectively. Now I can do this, but the average value of the pixel
is usually around 7000. For some reason the machine has only  calculated a
certain second of the film as having say 500 pixels. I need to use the by
function to calculate the mean pixels but I only want it to consider those
values of the pixel variable that are above 1000.

Does anyone know how I can modify the command I already have to make sure
this happens? Sorry it's a bit confusing but I find it hard to explain.
-- 
View this message in context: 
http://www.nabble.com/the-by-function-tp22723918p22723918.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@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.