+ Reply to Thread
Results 1 to 15 of 15

Thread: newbie question

  1. #1
    Points: 2,362, Level: 29
    Level completed: 42%, Points required for next Level: 88

    Posts
    25
    Thanks
    2
    Thanked 0 Times in 0 Posts

    newbie question



    Hi, I'm trying to import data into R and am having a problem.

    > D1<- read.table("rossi.txt",header=TRUE)
    > D1
    PB logDose
    1 97.55513 1.278754
    2 93.04890 1.591065
    3 83.36529 1.892095
    4 69.17546 2.193125
    5 50.14382 2.495544
    6 31.63950 2.812913
    7 17.97699 3.096910
    8 11.16970 3.397940
    > PB
    Error: object 'PB' not found
    >

    I'm trying to get it to spit out the first column when I type in PB and second column when I type in logDose... what am I missing?

  2. #2
    TS Contributor
    Points: 5,565, Level: 48
    Level completed: 8%, Points required for next Level: 185

    Location
    St Albans, UK
    Posts
    257
    Thanks
    0
    Thanked 7 Times in 5 Posts

    Re: newbie question

    The field names of the dataframe D1 are not searched by R so are not 'visible' as objects which is why you get the error message. However, you can use the attach and detach functions to force R to search a dataframe and make the field names visible or hide them, e.g. the following should work

    Code: 
    attach(D1)
    PB
    detach(D1)

  3. #3
    Points: 2,180, Level: 28
    Level completed: 20%, Points required for next Level: 120

    Location
    Chicago, IL
    Posts
    108
    Thanks
    1
    Thanked 19 Times in 15 Posts

    Re: newbie question

    Or, if you are planning on using multiple datasets that will have the same names for variables, you can call the columns without attaching them. Two methods:

    D1[,1]
    #(This calls the first column in dataset D1. Using [1,] would call the first row.

    D1$PB

  4. #4
    Points: 2,362, Level: 29
    Level completed: 42%, Points required for next Level: 88

    Posts
    25
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: newbie question

    Thank you for the replies. The method D1$PB worked well for me. I have another somewhat similar issue. I'm using the package "calib" to generate some logistic regressions (standard curve) for me and it's working great so far.

    Basically, in the end I get an answer from calib that gives me calculated concentrations of my unknowns using my standard curve equation-- I named this "w".

    > w

    An object of class calib
    Average.Response Estimated.Concentration Predicted.Standard.Error Inverse.Lower.CI Inverse.Upper.CI Wald.Lower.CI Wald.Upper.CI
    1 97.55513 19.59157 1.652979 16.78097 22.36679 16.06767 23.11547
    2 93.04890 37.61353 1.518184 34.79253 40.47084 34.37699 40.85007
    3 83.36529 79.29156 1.922243 75.87281 82.79054 75.19363 83.38949
    4 69.17546 155.33152 2.822214 150.27692 160.55549 149.31499 161.34804
    5 50.14382 314.22488 6.111968 303.61887 325.48170 301.19511 327.25466
    6 31.63950 638.30992 18.451222 606.40625 674.15453 598.97474 677.64510
    7 17.97699 1313.74110 79.047436 1185.86276 1486.15107 1145.22408 1482.25812
    8 11.16970 2363.21624 321.502282 1936.31595 NA 1677.82263 3048.60985

    Now I want to graph "Estimated.Concentration" vs some other variable, for instance. How do I extract that column into a data set? I tried to use "attach(w)" but that gives me an error.

  5. #5
    Points: 2,180, Level: 28
    Level completed: 20%, Points required for next Level: 120

    Location
    Chicago, IL
    Posts
    108
    Thanks
    1
    Thanked 19 Times in 15 Posts

    Re: newbie question

    You want to add the Estimated Concentration column to your original dataset?

    new.D1<-data.frame(D1, w$Estimated.Concentration))

    Would probably do the trick. I always check the dimensions of the new dataset and make sure they are what I expect them to be.

  6. #6
    Points: 2,362, Level: 29
    Level completed: 42%, Points required for next Level: 88

    Posts
    25
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: newbie question

    I think because of the first 2 lines which are text, the w$Estimated.Concentration isn't working.

    > new.D1<-data.frame(D2, w$Estimated.Concentration)
    Error in w$Estimated.Concentration :
    $ operator not defined for this S4 class
    > w$Estimated.Concentration
    Error in w$Estimated.Concentration :
    $ operator not defined for this S4 class

  7. #7
    RotParaTon
    Points: 46,287, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardFrequent PosterCommunity AwardMaster Tagger
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,083
    Thanks
    211
    Thanked 1,609 Times in 1,379 Posts

    Re: newbie question

    Does this work?
    Code: 
    cbind(D1, w$Estimated.Concentration)

  8. #8
    Points: 2,362, Level: 29
    Level completed: 42%, Points required for next Level: 88

    Posts
    25
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: newbie question

    > cbind(D1, w$Estimated.Concentration)
    Error in w$Estimated.Concentration :
    $ operator not defined for this S4 class

    No. Basically, I want to tell R to ignore the first 2 lines from "w", which is a blank line and a description. The third line contains the headers and the 4th line has the actual data (if this is actually the problem I think it is). BTW, this is the error I get using "attach"

    > attach(w)
    Error in attach(w) :
    'attach' only works for lists, data frames and environments
    Last edited by toothpicky; 03-03-2011 at 03:06 PM.

  9. #9
    RotParaTon
    Points: 46,287, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardFrequent PosterCommunity AwardMaster Tagger
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,083
    Thanks
    211
    Thanked 1,609 Times in 1,379 Posts

    Re: newbie question

    I don't have that package available and probably will never install it. But using str can work wonders. My guess is that the data frame is inside the object you want and you just have to specify it.
    So try something like
    Code: 
    str(w$Estimated.Concentration)
    to see what's actually inside that object.

  10. #10
    Points: 2,180, Level: 28
    Level completed: 20%, Points required for next Level: 120

    Location
    Chicago, IL
    Posts
    108
    Thanks
    1
    Thanked 19 Times in 15 Posts

    Re: newbie question

    What class is the object? use: class(w)

    If it is a matrix or data frame and you definitely want the second column of Estimated.Concentration, excluding the first two rows, you can probably use:

    new.D1<-data.frame(D1, w[3:10, 2])

  11. #11
    Points: 2,362, Level: 29
    Level completed: 42%, Points required for next Level: 88

    Posts
    25
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: newbie question

    Hello janus,

    > class(w)
    [1] "calib"
    attr(,"package")
    [1] "calib"
    > new.D1<-data.frame(D1, w[3:10, 2])
    Error in w[3:10, 2] : object of type 'S4' is not subsettable

    I guess the output from calib isn't too friendly. I tried to turn it to data frame but no avail.

    > k<-as.data.frame(w)
    Error in as.data.frame.default(w) :
    cannot coerce class 'structure("calib", package = "calib")' into a data.frame

    Also, Dason, this is what I get with your command:

    > str(w$Estimated.Concentration)
    Error in w$Estimated.Concentration :
    $ operator not defined for this S4 class

    Not too useful, unfortunately. Is there a better way to do it than copy and paste my output into Excel, use the text to column command to get a real data set I can use? Sounds pretty bad if I have to resort to that.

  12. #12
    RotParaTon
    Points: 46,287, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardFrequent PosterCommunity AwardMaster Tagger
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,083
    Thanks
    211
    Thanked 1,609 Times in 1,379 Posts

    Re: newbie question

    ohhh I sort of see what's going on. ok. Do this instead
    Code: 
    str(w)
    w is actually the S4 object. It's a good skill to try to read the error messages that R gives you. They can typically help you diagnose what the problem is.
    Last edited by Dason; 03-03-2011 at 03:55 PM.

  13. #13
    Points: 2,362, Level: 29
    Level completed: 42%, Points required for next Level: 88

    Posts
    25
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: newbie question

    > str(w)
    Formal class 'calib' [package "calib"] with 22 slots
    ..@ Estimated.x : num [1:8] 19.6 37.6 79.3 155.3 314.2 ...
    ..@ PredStdErr : num [1:8] 1.65 1.52 1.92 2.82 6.11 ...
    ..@ inver.low : num [1:8] 16.8 34.8 75.9 150.3 303.6 ...
    ..@ inver.up : num [1:8] 22.4 40.5 82.8 160.6 325.5 ...
    ..@ wald.low : num [1:8] 16.1 34.4 75.2 149.3 301.2 ...
    ..@ wald.up : num [1:8] 23.1 40.9 83.4 161.3 327.3 ...
    ..@ avg.response: num [1:8] 97.6 93 83.4 69.2 50.1 ...
    ..@ dilution : num [1:8] 1 1 1 1 1 1 1 1
    ..@ oor : chr [1:8] "o" "o" "o" "o" ...
    ..@ lmdc : chr [1:8] "O" "O" "O" "O" ...
    ..@ row.names : chr(0)
    ..@ labels :List of 9
    .. ..$ name : chr "Sample"
    .. ..$ plot.ind : int [1:8] 1 2 3 4 5 6 7 8
    .. ..$ too.low : logi [1:8] FALSE FALSE FALSE FALSE FALSE FALSE ...
    .. ..$ too.high : logi [1:8] FALSE FALSE FALSE FALSE FALSE FALSE ...
    .. ..$ xlabs : chr [1:8] "1" "2" "3" "4" ...
    .. ..$ cont.pl : logi FALSE
    .. ..$ xunits : chr ""
    .. ..$ dose.units: chr ""
    .. ..$ dose.name : chr ""
    ..@ max.x : num 2500
    ..@ extrap : logi FALSE
    ..@ repeq : logi TRUE
    ..@ rname : chr "response"
    ..@ conf.level : num 0.9
    ..@ type : chr(0)
    ..@ mdc : num 8.65
    ..@ truth : NULL
    ..@ times : NULL
    ..@ samp.names : NULL


    That looks cool. I think you're onto something.

  14. #14
    RotParaTon
    Points: 46,287, Level: 100
    Level completed: 0%, Points required for next Level: 0
    Awards:
    Discussion EnderPosting AwardFrequent PosterCommunity AwardMaster Tagger
    Dason's Avatar
    Location
    Ames, IA
    Posts
    9,083
    Thanks
    211
    Thanked 1,609 Times in 1,379 Posts

    Re: newbie question

    So it looks like what you really want is
    Code: 
    w@Estimated.x

  15. #15
    Points: 2,362, Level: 29
    Level completed: 42%, Points required for next Level: 88

    Posts
    25
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Re: newbie question


    Quote Originally Posted by Dason View Post
    So it looks like what you really want is
    Code: 
    w@Estimated.x
    Perfect! Thank you so much.

+ Reply to Thread

Similar Threads

  1. Replies: 2
    Last Post: 03-29-2011, 09:52 AM
  2. newbie question about questionnaires
    By logical in forum Psychology Statistics
    Replies: 1
    Last Post: 04-30-2009, 12:33 PM
  3. Newbie with a question
    By TheQueenOfStyrene in forum Statistics
    Replies: 3
    Last Post: 10-12-2007, 08:10 PM
  4. Newbie question - repeated measures and non-parametrics
    By kpugh in forum Psychology Statistics
    Replies: 2
    Last Post: 10-04-2006, 02:16 PM
  5. Newbie Here! Question on find number of test...
    By redevo7 in forum Statistics
    Replies: 1
    Last Post: 04-05-2006, 10:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts








Advertise on Talk Stats