s-news
[Top] [All Lists]

Re: data manipulation

To: "Zheng_Jenny" <Zheng_Jenny@Allergan.com>
Subject: Re: data manipulation
From: David L Lorenz <lorenz@usgs.gov>
Date: Fri, 27 Oct 2006 13:58:26 -0500
Cc: s-news@lists.biostat.wustl.edu, s-news-owner@lists.biostat.wustl.edu
In-reply-to: <D475C767BF2F6D438FD30E3984FCBB11028A8E95@irmail121.irvine.allergan.com>

Jenny,
  You are getting the error because ID2 is a factor and there is no level "zero." You have 2 choices: 1 redo the ID2 column and add a level "zero" or convert ID2 to character.
  Note that you can prevent automatic conversion of character to factor by specifying stringsAsFactors=F as an argument in data.fame(). You can also set that as a global option, but probably do not want to.
Dave


"Zheng_Jenny" <Zheng_Jenny@Allergan.com>
Sent by: s-news-owner@lists.biostat.wustl.edu

10/27/2006 01:33 PM

To
<s-news@lists.biostat.wustl.edu>
cc
Subject
[S] data manipulation





Hi, everyone,
Would anyone help me with the problem below?
 
I have a dataset x including ID, Time, DV and ID2.
 
I can use
x$DV[x$Time==0]_0 to make DV=0 when Time is 0 but when I was trying to use command “x$ID2[x$Time==0]_"zero"” to make ID2==zero when Time is 0, I received the following message”
 
Warning messages:
  replacement values not all in levels(x): NA's generated in: .A0[x$Time ==
   0]  <-  "zero"
 
Why is that? How can I do what I want to do? What would be effective command to change DV=0 when time is 0,2 and 4. Thanks in advance.
 
 
 
Jenny
 
 
x_data.frame(ID=seq(1,10,1),Time=rep(c(0,1,2,3,4),2),DV=rnorm(10,0,1),ID2=rep(sample(letters,5),2))
x$DV[x$Time==0]_0
x$ID2[x$Time==0]_"zero"
Warning messages:
  replacement values not all in levels(x): NA's generated in: .A0[x$Time ==
   0]  <-  "zero"
 
 
 
<Prev in Thread] Current Thread [Next in Thread>