Abbreviating variables in R [closed] - r

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I am using a data set called Forbes2000 which is provided by the package HSAUR. I am able to plot the data but not able to abbreviate each point with the corresponding country name. Here is the code I have tried:
Forbes2000top50ccompanies <- head(Forbes2000[order(Forbes2000$profits, decreasing= T),], n = 50)
plot(sales ~ assets,data=Forbes2000top50ccompanies)

This will give you labels that are the first 4 letters of the country names and make them smaller than would be the default:
with(Forbes2000top50ccompanies,
text(x=assets, y=sales,
labels=substr(Forbes2000top50ccompanies$country, 1, 4), cex=0.6) )

Related

Solving linear equation in one variable in R [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
How do we find the solution of x
say in
2*x=6
using R?
It must be very trivial but I cant find out the appropriate answer.
You can use the solve() function, which can actually handle multiple equations:
solve(2, 6)
The first argument is the left side of the equation, the second is the right side.

change data in column [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I have boxscore data from the NFL and some of the data is obviously incorrect. For example for some games the number of sacks is negative, which is impossible. This column is named SackNumOff. How do I change any negative values in this column to zero?
Something like this:
dat$columnname[dat$columnname < 0] = 0
Replaces all negative numbers by 0. The idea is that you can use a subset [] both to extract a subset and assign values to a subset.

Limitation on number of items in c() function in R [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
There seems to be a limit to number of items that can be included in c() function in R (100 items).
Is there any way to evade this limitation?
Thanks in advance.
There is a limit, but it is a limit of vector length, not a limitation of c:
length(eval(call('c', 1:(2^31-1))))
## [1] 2147483647
length(eval(call('c', 1:(2^31))))
## Error in 1:(2^31) : result would be too long a vector

Replace contents of multiple cells in a dataframe [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I need to replace the contents of multiple cells in a dataframe. Using mtcars as an example, how would I replace any cells which contain 1 with one in the vs column?
mtcars$vs[mtcars$vs == 1] <- "one"
or
mtcars[mtcars$vs == 1, "vs"] <- "one"
Something like this:
mtcars$vs[mtcars$vs == 1] <- "one"

How can I change the point color in densityplot (lattice)? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
By points, I mean the points on the bottom of the densityplot. Furthermore, I would like to set some value of "jitter", such that all the points are not just on a straight line and more "scattered" around.
With lattice, it is often helpful to look at the panel version of help functions ?panel.densityplot, which mentions jitter.amount; I admit to peeking at the source for panel.density to see that points are plotted using panel.xyplot, which has argument col.symbol. So
library(lattice)
x = rnorm(1000)
densityplot(x, jitter.amount=.02, col.symbol="red")

Resources