bryan

Forum Replies Created

Viewing 15 posts - 1 through 15 (of 38 total)
  • Author
    Posts
  • in reply to: applying if then else logic to a column in a data frame #1077
    bryan
    Participant

    Also, as I look at your code again, I’m not clear how the groups should be defined in your DOLGX objects. If you’re just trying to classify based on ranges (not specific discrete values), you can set your ifelses up as so:

    DOL.group < - ifelse(Clean.Data$DOL >= .005 & Clean.Data$DOL <= .01 , DOL.Group = 1, NA), etc.

    in reply to: applying if then else logic to a column in a data frame #1076
    bryan
    Participant

    Hi sander,

    Welcome to R and ProgrammingR.com. A couple of suggestions:

    1) Directly related to your question: use multiple ifelse() functions to create your groups. E.g,

    DOL.group <- ifelse(Clean.Data$DOL %in% DOLG1, DOL.Group = 1, NA) DOL.group <- ifelse(Clean.Data$DOL %in% DOLG2, DOL.Group = 2, DOL.Group) DOL.group <- ifelse(Clean.Data$DOL %in% DOLG3, DOL.Group = 3, DOL.Group) Since ifelse() operates on vectors, you do not need to iterate through each row with a loop. There are other ways to do what you're asking, but this is a fine, straightforward way to handle it. 2) It's almost always a good idea to include stringsAsFators = 'FALSE' in your import command. It usually makes your data manipulations easier and less error prone, unless you are comfortable working with factors. 3) attach() can be more trouble than it is worth most of the time. I recommend against using it. I suspect 1) will fix your issue, but let us know if not. Bryan

    in reply to: Please help me with this graph code #1062
    bryan
    Participant

    Hi Carolina,

    Since the parameters for the text function in your code are specified by position, the piece that’s directly causing that error is this:

    paste(firstdiff,lastdiff,sep=”-”)

    Check that you have what you expect in the firstdiff and lastdiff objects.

    Bryan

    in reply to: Weird data issue #1055
    bryan
    Participant

    Glad you got it figured out. The stringAsFactors=TRUE is one of the most inexplicable defaults I’ve encountered.

    Here’s an interesting, short and relevant Stack Overflow question:

    http://stackoverflow.com/questions/8177921/how-to-disable-stringsasfactors-true-in-data-frame-permenantly

    in reply to: missing columns and rows in my matrix #1028
    bryan
    Participant

    Hi Sarah,

    Can you provide a little more information, for example, the output from str(your.matrix) and your code?

    Bryan

    in reply to: Absolute Beginner In R-Need Help! #1026
    bryan
    Participant

    That one you’ll have to purchase, but it is worth the money in my opinion. Everything else on those lists is a web page or (free) downloadable PDF.

    in reply to: Absolute Beginner In R-Need Help! #1023
    bryan
    Participant

    Rahul,

    For true novices, I recommend a book I reviewed about a year ago. It is a “for Dummies” book, but as I mention in my review, it covers the basics and several important advanced topics. The review is posted here:

    http://programmingr.com/content/r-for-dummies-de-vries-and-meys-2012/

    Beyond that, there are many, many free resources on the web. Here are some that are either “required reading” (e.g., R Inferno) or otherwise good, concise collections. The first link covers primarily statistics topics, the second covers R programming.

    http://programmingr.com/content/helpful-statistical-references/

    http://programmingr.com/content/online-r-programming-resources/

    Best of luck, and don’t hesitate to return with questions as you progress.

    Bryan

    in reply to: Absolute Beginner In R-Need Help! #1021
    bryan
    Participant

    Hi,

    Welcome to ProgrammingR.com and R in general. R programming is a very marketable skill these days. Not only that, but learning R would likely help you with your analytic skills, in general. Are you looking for resources for learning R or just some thoughts on whether it is worthwhile for your situation?

    Regards,
    Bryan

    bryan
    Participant

    Hi tovy,

    The R idiomatic way to do this is to use an ifelse() statement:

    Course$grade2 <- ifelse(Course$grade >= median(Course$grade), 1, 0)

    For more information on ifelse() you can type ?ifelse at a prompt or just ask here.

    HTH,
    Bryan

    • This reply was modified 6 years, 8 months ago by bryan. Reason: typo
    in reply to: Unable to write data into file #969
    bryan
    Participant

    Hi Chai,

    This is a path issue. My guess is you want something like:

    write(data7, file = ‘~/Desktop/data7.txt’, sep = ‘,’)

    Note the added tilde and forward slash.

    Just repost if that doesn’t help.

    • This reply was modified 7 years, 1 month ago by bryan.
    in reply to: Writing to a file through a loop #968
    bryan
    Participant

    Hi Joepaul,

    Yes, the pdf call is likely the problem. Try:

    pdf(paste(x, ".pdf", sep=''))

    Technically, you don’t need the extra counter (e.g., x) Just use your iterator variable/index:

    pdf(paste(i, ".pdf", sep=''))

    in reply to: Useful R helper functions #837
    bryan
    Participant

    That’s definitely a task we run into often; anything to make that easier is helpful.

    in reply to: Data Manipulation/Flow Control #722
    bryan
    Participant

    Don,

    Is the switch() function what you need?

    http://cran.r-project.org/doc/manuals/R-lang.html#switch

    in reply to: Counting rows #703
    bryan
    Participant

    That’s true, the base summary function will work. I’ve gotten in the habit of using the doBy package because it has a few other functions that are helpful, too, but for a simple grouping what you have is fine.

    Do you mean you want to select cases where TZE_D_LOK begins with “^C51”, such as “^C51A”, “^C51B”, “^C51C”…?

    In that case you can use grep. This is untested, but something like this should work:

    summary(TZE_D_LOK, data = daten[grepl(pattern="^C51", x=daten$TZE_D_LOK, fixed=TRUE),], FUN = length)

    in reply to: Counting rows #693
    bryan
    Participant

    Keep in mind that R is case sensitive – I think your primary problem is that you’ve capitalized the “D” and not the “B” in “doBy”. But the warnings suggest that you might be having trouble with your internet connection as well. Checking/fixing those two things should fix it.

Viewing 15 posts - 1 through 15 (of 38 total)