Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I'm new to R. I would like to know how I can create an array with two dimensions, the first being a numeric matrix and the second a character matrix?
Thanks.
An array cant have multiple datatypes. What you are looking for is the dataframe.
For example, you can create a dataframe with a numeric and a character column like this:
df <- data.frame(numericColumn=1:26,characterColumn=LETTERS)
To access these columns, you can use square brackets or the names. For more details, just read the documentation of dataframe or search for some examples.
If you really want to store matrices of different types in one object, you can use a list, for example like
matrixList <- list(numericMatrix=someNumericMatrix,characterMatrix=someCharacterMatrix)
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
How come I am able to pass a dataframe into the dparams argument of the geom_qq() function, when it is specified as a list type argument?
Is it because a dataframe is technically a list of equal length vectors?
I would say so. A data frame can in general be treated like a list, not necessarily the other way around though.
Without knowing your data, your general idea is correct.
See also:
http://www.r-tutor.com/r-introduction/data-frame
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have 2 dataframe objects with common transcript names. The names are out of order for each other, and as such I am trying to index into them and pull out the rows based off from this first column of transcript names to organize the data. I want to retain all of the different values in the other columns, but just reorder the data based off from the indices. I am trying to do this in R.
In MATLAB I can do this by using intersect to find the indices.
Sounds like you want to merge on transcript name. As in df.new <- merge(df.1,df.2,by="transcript.name"). This will merge the observations (rows) that are common to both data frames. If you want to retain all the observations from the first data frame (df.1), even if they're not in df.2, then include all.x=TRUE.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have written the following code to compare Two Market, the code is working if we provide the Data Frame name individually.
enter image description here
for(i in 1:nrow(Market_SystemA))
{
A <- Market_SystemA[i,2]
B <- Market_SystemB[i,3]
MarketA <- data.frame(A)
MarketB <- data.frame(B)
#This is s fuction in R
Compare_Function(MarketA,MarketB)
}
I'm not sure if I understand your question correctly, but it seems like you are calling a compare_function on two strings that refer to existing data frames. To actually get the data frames from the string, then you will need to use the get function which looks for an object that has a name that matches the string.
MarketA <- get(A)
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am quite new to R and it would be a big help to find a way to do this.
I have a list of values(just one Column and around 16000 values) and I have to break this list up into smaller packets of 1000 values each. Then save each list as a csv file.
Is there a way of doing this is R?
Thank you in advance,
Dgupta
Something like this:
data <- as.data.frame(list)
groups <- split(1:nrow(data), ceiling(seq_along(1:nrow(data)/1000))
for (i in 1:length(groups)){write.csv(data[groups[1,],file=paste(i,'csv'))}
You can split the vector up by using a colon symbol in the vector index. For example:
> x <- c(10,20,30,40)
> x[1:2]
[1] 10 20
you can then write a vector to a csv by using the write.csv()function. One way to approach this is to write loop that gets 1000 items at a time from the vector and writes it to a csv.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Without using a special function, can you do the following to change the values in an R dataframe from a column that have length greater than 4:
df[length(df$Column1)>4,"Column1"] = "replacement value"
This does not seem to work, is there an alternative index style I can use, or do I need to use a function?
Thanks
The function to determine the length of an entry, like a word in a dataframe, is nchar(), and not length(). The latter is typically used to determine the number of entries in a vector.
You could therefore try using:
df[nchar(df$Column1) > 4, "Column1"] <- "replacement value"